nginx 基于tcp

nginx从1.9.0版本开始,新增了ngx_stream_core_module模块,使nginx支持四层负载均衡。默认编译的时候该模块并未编译进去,需要编译的时候添加--with-stream,使其支持stream代理。

Nginx 基于tcp/udp代理

Nginx


nginx 基于tcp/udp代理



nginx从1.9.0版本开始,新增了ngx_stream_core_module模块,使nginx支持四层负载均衡。默认编译的时候该模块并未编译进去,需要编译的时候添加--with-stream,使其支持stream代理。

同时需要说明一点,nginx也可以代理tcp的正向代理和反向代理,我这里主要以反向代理为基础,需要正向代理可以参考 Nginx 反向代理与正向代理

官方文档stream模块地址:http://nginx.org/en/docs/stream/ngx_stream_core_module.html

因为手上没有合适的环境,我这里设置nginx代理smtp。使用腾讯的smtp服务进行代理演示

Nginx搭建

<code>1.nginx版本没有太大要求,1.9以上即可wget http://nginx.org/download/nginx-1.10.3.tar.gz#按照依赖包yum install -y gcc glibc gcc-c++ prce-devel openssl-devel pcre-develuseradd -s /sbin/nologin nginx -M tar xf nginx-1.10.3.tar.gz && cd nginx-1.10.3#编译./configure --prefix=/usr/local/nginx-1.10.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-streammake && make install检查/usr/local/nginx/sbin/nginx -t启动/usr/local/nginx/sbin/nginx查看服务器是否启动netstat -lntp|grep nginx    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      7058/nginx: master/<code>

配置Nginx

stream不可以配置在http标签,需要和events同级,我这里就单独写一份配置文件,也方便后期维护管理

<code>1.首先需要修改nginx.conf,添加include 引用server标签cat >/usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/i4t.com /<code>
<code>1.首先需要修改nginx.conf,添加include 引用server标签cat >/usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/i4t.com /<code>
<code>1.首先需要修改nginx.conf,添加include 引用server标签cat >/usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/i4t.com /<code>


分享到:


相關文章: