基础环境
跳板机,IP:192.168.3.174
控制机01,IP:192.168.2.78
控制机02,IP:192.168.2.79
控制机01、控制机02只允许跳板机访问。
nginx安装
这里使用docker-compose安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | version: '3.7'
services:
nginx:
restart: always
image: registry.cn-hangzhou.aliyuncs.com/eddy/nginx:1.27
privileged: true
environment:
TZ: Asia/Shanghai
ports:
- 8001:8001
- 2201:2201
- 2202:2202
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./http:/etc/nginx/http
- ./stream:/etc/nginx/stream
- ./logs:/etc/nginx/logs
|
检查NGINX支持STREAM模块
1 2 3 4 5 | docker exec -it [容器名] /bin/sh
nginx -V 2>&1 | grep -o with-stream
|
配置NGINX转发TCP流量
在Nginx配置文件(如 /etc/nginx/nginx.conf)中添加 stream 块(与 http 块同级)
1 2 3 4 5 6 7 8 9 10 11 12 | worker_processes 1;
error_log /etc/nginx/logs/error.log;
events {
worker_connections 1024;
}
stream {
include /etc/nginx/stream/*.conf;
}
|
1 2 3 4 5 | server {
listen 2201;
proxy_pass 192.168.2.78:22;
}
|
1 2 3 4 5 | server {
listen 2202;
proxy_pass 192.168.2.79:22;
}
|
重启Nginx即可
大功告成,开始享用吧
切忌,该方式不适合生产使用,存在安全风险!