首页 > 服务器    日期:2018-08-20 / 来自互联网 / 浏览

Nginx1.90做TCP代理和协议负载均衡的功能

nginx从1.9.0开始增加了stream模块(ngx_stream_core_module),默认configure不包含该模块,需要在configure的时候加上--with-stream

./configure --prefix=/usr/local/nginx --user=www --group=www 
--add-module=/root/ngx_http_google_filter_module 
--add-module=/root/ngx_http_substitutions_filter_module 
--with-http_stub_status_module 
--with-http_v2_module 
--with-http_ssl_module 
--with-ipv6 
--with-http_gzip_static_module 
--with-http_realip_module 
--with-http_flv_module 
--with-http_sub_module 
--with-stream

配置文件很简单,最基本的

.....................
events {
use epoll;
worker_connections 51200;
}
stream {
server {
listen 2002;
proxy_pass 123.123.123.123:3389;
}
server {
listen 2003;
proxy_pass 123.123.123.123:22;
}
}
http {
.....................

需要在防火墙允许相应的端口通过。这样可以反代远程桌面3389端口或者其他固定的TCP端口,比iptables转发或者虚拟专用网络连接来管理国外Windows或者Linux服务器要方便不少。

当然,该模块最重要的功能是支持TCP负载均衡,比如远程多台mysql负载均衡。

stream {
upstream mysql {
server 1.1.1.1:3306;
server 2.2.2.2:3306;
server 3.3.3.3:3306;
}
server {
listen 3306;
proxy_pass mysql;
}
}

官方文档http://nginx.org/en/docs/stream/ngx_stream_core_module.html

觉得上面的内容有用吗?快来点个赞吧!

点赞() 我要打赏

温馨提示 : 本站内容来自会员投稿以及互联网,所有源码及教程均为作者总结编辑,请大家在使用过程中提前做好备份,以免发生无法预知的错误,源码类教程请勿直接用于生产环境!

 可能感兴趣的文章