zoukankan      html  css  js  c++  java
  • nginx的四层代理

    nginx通过四层代理实现端口转发

    需要两台虚拟机,一台用作nginx代理(安装 --with-stream模块  192.168.200.113),一台用作测试访问(安装nginx,写测试文本  192.168.200.112),目的是通过访问代理机的300端口可以访问到测试机的80端口。

    测试机就是Web服务器,可以是nginx的80端口,apache的80端口,tomcat的8080端口。

    一、nginx代理机(192.168.200.113)

    [root@localhost ~]# yum -y install pcre-devel zlib-devel openssl-devel
    [root@localhost ~]# useradd -M -s /sbin/nologin nginx
    [root@localhost ~]# tar -xf nginx-1.15.9.tar.gz -C /usr/src/
    [root@localhost ~]# cd /usr/src/nginx-1.15.9/
    编译安装,安装所需模块
    [root@localhost nginx-1.15.9]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-stream && make && make install    
    [root@localhost nginx-1.15.9]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
    events {
        worker_connections  1024;
    }
    
    stream {
        server {
           listen 300;     //通过本机的300端口访问
           proxy_pass 192.168.200.112:80;    //可以访问到112主机上的80端口
        }
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
    [root@localhost ~]# nginx

    二、安装nginx

    省略安装过程,编写测试文件如下:

    [root@localhost ~]# cat /usr/local/nginx/html/index.html 
    bbbbbb

    三、测试

  • 相关阅读:
    Jenkins历史构建作业jobs的删除与管理
    Redis消息队列与主流的消息队列中间件对比
    GDAL数据模型
    Android的语言切换
    GDAL驱动实现向导
    Win7 安装IIS
    局域网中其他机器不能访问本机IIS网站
    DXF库(dxflib)使用指南
    GDAL中文学习资料
    QT的中文站址
  • 原文地址:https://www.cnblogs.com/tanxiaojuncom/p/11640082.html
Copyright © 2011-2022 走看看