系统相关
首页 > 系统相关> > nginx实现tcp的反向代理

nginx实现tcp的反向代理

作者:互联网

 nginx不仅可以实现http的反向代理,同时也支持TCP的反向代理
以SSH为例
1.编译的时候需要加入--with-stream这个参数,以加载ngx_stream_core_module这个模块
2.vim nginx.conf
注意要加在http之上,不能加在http里面
stream {
upstream tcp_proxy{
hash $remote_addr consistent;
server 192.168.56.12:22
}

server {
listen 2222 so_keepalive=on;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass tcp_proxy;
}
}
这段话的意思为:监听本机的2222端口,实现跳转到192.168.56.12的22号端口

ssh -p 2222 192.168.56.11 就会跳转到192.168.56.12 

标签:stream,2222,192.168,nginx,反向,proxy,tcp,56.12
来源: https://www.cnblogs.com/zhubochang/p/11309529.html