最近整理家里的 NAS 环境,建了一台虚拟机作为所有服务对外的出口,使用了 Nginx 反向代理 来转发分散在各机器上的服务。

所有 web 服务都配置正常,尝试转发 ssh (22) 端口的时候出现了问题,所有查看了一下文档,发现不能配置在 http 下,需要在 stream 下配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
stream {
upstream centos7 {
server 192.168.1.6:22;
}

upstream mongodb {
server 192.168.1.4:27017;
}

server {
listen 3062;
proxy_pass centos7;
proxy_connect_timeout 1d;
proxy_timeout 1d;
}

server {
listen 27017;
proxy_pass mongodb;
proxy_connect_timeout 1d;
proxy_timeout 1d;
}
}

这样就完成了对 ssh 和 mongodb 的转发,其他类似的需求也能通过这种方式完成,比如远程桌面啥的~