0%

nginx 端口转发

nginx 端口转发 (达到frp效果)

nginx配置

配置文件内容

1
2
3
4
5
6
7
8
9
10
11
# /usr/local/openresty/nginx/conf/nginx.conf
events {
worker_connections 1024;
}

#### 核心是该行,和http同级
include /usr/local/openresty/nginx/conf/stream.d/*.conf;

http {
include mime.types;
default_type application/octet-stream;

子端口配置 tcp.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
stream {
server {
listen 5222;
proxy_pass 103.145.23.28:5222;
}
}

#stream {
# upstream backend {
# server backend1.example.com:12345;
# server backend2.example.com:12345;
# }
#
# server {
# listen 12345;
# proxy_pass backend;
# }
#}

参考

  1. 使用Nginx转发TCP/UDP
  2. 使用Nginx进行TCP/UDP端口转发