让lnmp支持3389转发或者支持多个端口的TCP流量

/ 0评 / 0

这个方法Sandy一直在用,最近芳姐和大哥问起来来。所以就发出来给大家看看!

起因:一直在用国外的杜甫,但是win下的3389非常的卡。之前用frp方案,后来发现frp吃端口。一个frp下去一台服务器的端口基本废了。所以才想到在nginx下搞事情!

调试

环境:lnmp 1.5以上,1.5以下需要自己安装stream。

1、查看stream模块

测试你的nginx是不是支持stream模块

nginx -V |grep with-stream

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

nginx version: nginx/1.18.0
built by gcc 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)
built with OpenSSL 1.1.1g  21 Apr 2020
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-openssl=/root/lnmp1.7/src/openssl-1.1.1g --with-openssl-opt='enable-weak-s

既然支持我们就开整!

2、修改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;  #转发请求
    }
}

3、重启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;  #转发请求
    }
}

发表评论

邮箱地址不会被公开。 必填项已用*标注