PRIVATE DIGITAL GARDEN

在折腾里, 记录世界。 知名博客|折腾博客|心爱的⎛⎝xinai.de⎠⎞
Linux系统ARTICLE · 83333

使用nginx的stream模块实现端口转发和TCP流量

用国外的VPS或者服务器远程桌面有时候非常卡,寥寥一直在用这个转发,今天他写了文章,我就直接copy过来了,版权所有MJJ廖。

1、三选一:
单独装nginx,自己编译stream模块组件;
安装lnmp1.5或者1.5以上,低于1.5版本自己要编译组件
宝塔面板安装nginx

2、查看stream模块
测试你的nginx是不是支持stream模块

nginx -V |grep with-stream

出现这样的–with-stream字样,说明就是支持的!

3、nginx支持组件的话就开搞,修改nginx.conf文件
找到/usr/local/nginx/conf/nginx.conf, 在events上面加入stream配置

stream {
    upstream bi_remote_desk {
        # simple round-robin 转发IP和端口
        server 10.10.10.10:3389;
        #check interval=3000 rise=2 fall=5 timeout=1000;
        #check interval=3000 rise=2 fall=5timeout=1000
        #check interval=3000 rise=2 fall=5timeout=1000
        #check_http_send "GET /HTTP/1.0\r\n\r\n";
        #check_http_expect_alive http_2xxhttp_3xx;
    }
    server {
        listen 3389; ##监听端口
        proxy_pass bi_remote_desk;  #转发请求
    }
}

4、重启lnmp
重启lnmp restart,就可以远程你的机器了!
最后是寥寥分享的定义多个端口转发

stream {
    upstream bi_remote_desk {
        # simple round-robin 转发IP和端口
        server 10.10.10.10:3389;
        #check interval=3000 rise=2 fall=5 timeout=1000;
        #check interval=3000 rise=2 fall=5timeout=1000
        #check interval=3000 rise=2 fall=5timeout=1000
        #check_http_send "GET /HTTP/1.0\r\n\r\n";
        #check_http_expect_alive http_2xxhttp_3xx;
    }
    server {
        listen 3389; ##监听端口
        proxy_pass bi_remote_desk;  #转发请求
    }
    upstream 214_ssh {
        server 10.10.10.10:22;
    }
    server {
        listen 105; ##监听端口
        proxy_pass 214_ssh;  #转发请求
    }
}

原文链接https://blog.e9china.net/share/lnmp-stand-by-3389-forward.html
又学习新姿势了,^_^,enjoy!

0

0 条评论

想法、补充或纠错,都欢迎写下来。

成为第一个评论的人

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理