Nginx作为TCP/UDP的负载均衡

栏目: 服务器 · Nginx · 发布时间: 5年前

内容简介:从Nginx 1.9开始,nginx也可以支持TCP/UDP的负载均衡,当然前提是编译的时候 把stream这个模块编译进去了,可以通过如果有,则使用如下配置便可以:其中listen是监听本地的什么IP以及端口,proxy_pass则是需要代理的目标服务器IP和端口。具体的 参数可以看参考中列出的文档。

从Nginx 1.9开始,nginx也可以支持TCP/UDP的负载均衡,当然前提是编译的时候 把stream这个模块编译进去了,可以通过 nginx -V 来查看是否有:

$ nginx -V 2>&1 | grep stream
configure arguments: --prefix=/etc/nginx --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/bin/nginx --pid-path=/run/nginx.pid --lock-path=/run/lock/nginx.lock --user=http --group=http --http-log-path=/var/log/nginx/access.log --error-log-path=stderr --http-client-body-temp-path=/var/lib/nginx/client-body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-cc-opt='-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -D_FORTIFY_SOURCE=2' --with-ld-opt=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now --with-compat --with-debug --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-pcre-jit --with-stream --with-stream_geoip_module --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads

如果有,则使用如下配置便可以:

stream {
    server {
        listen 12345;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass 192.168.1.1:8080;
    }
}

其中listen是监听本地的什么IP以及端口,proxy_pass则是需要代理的目标服务器IP和端口。具体的 参数可以看参考中列出的文档。

Nginx真是越来越强大了!

参考:


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

大教堂与集市

大教堂与集市

[美] Eric S. Raymond / 卫剑钒 / 机械工业出版社 / 2014-5 / 59.00元

当代软件技术领域最重要的著作,中文版首次出版! 《大教堂与集市》是开源运动的《圣经》,颠覆了传统的软件开发思路,影响了整个软件开发领域。作者Eric S. Raymond是开源运动的旗手、黑客文化第一理论家,他讲述了开源运动中惊心动魄的故事,提出了大量充满智慧的观念和经过检验的知识,给所有软件开发人员带来启迪。本书囊括了作者最著名的“五部曲”,并经过作者的全面更新,增加了大量注释,提高了可读......一起来看看 《大教堂与集市》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具