nginx不仅可以实现http的反向代理,同时也支持TCP的反向代理
前提
编译的时候需要加入–with-stream这个参数,以加载ngx_stream_core_module这个模块
vim nginx.conf
注意要加在http之上,不能加在http里面
实例:
stream {
upstream tcp_proxy{
hash $remote_addr consistent;
server 192.168.56.12:10960
}
server {
listen 18098 so_keepalive=on;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass tcp_proxy;
}
}