1.nginx必须是1.9.0以上的版本,如果低于这个版本,需要额外打补丁,比较麻烦。
2.nginx(1.9.0以上的版本)编译的时候一定要带上 --with-stream --with-stream_ssl_module这两个模块,当然如果线上的nginx没有这两个模块,可以平滑添加模块,不用停机。
3.配置相关:
(1)nginx.conf
配置文件里,添加如下内容,stream配置跟http配置是对等的关系,所以要跟http分开。
stream {
log_format proxy '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
access_log /var/log/nginx/tcp-access.log proxy ;
open_log_file_cache off;
include /usr/local/nginx/conf/conf.d/*.stream;
}
(2)具体的反向代理配置文件,这个其实跟http的配置方式一样。
upstream xxx_base{
server 10.0.1.1:8890;
}
server {
listen 8890;
proxy_connect_timeout 5s;
proxy_timeout 30s;
proxy_pass xxx_base;
access_log /var/log/nginx/xxx_base_tcp.access.log proxy;
error_log /var/log/nginx/xxx_base_tcp.error.log;
}
配置与优化:Nginx 1.9.0以上版本的Stream模块与反向代理
本文介绍了如何确保Nginx版本不低于1.9.0并添加stream模块,强调了编译时必须包含--with-stream--with-stream_ssl_module。此外,详细展示了配置stream模块的步骤,包括日志格式、反向代理设置,以及如何平滑添加模块,实现不停机更新。
850

被折叠的 条评论
为什么被折叠?



