基础环境
- 跳板机,ip:192.168.3.174
- 控制机01,ip:192.168.2.78
- 控制机02,ip:192.168.2.79
控制机01、控制机02只允许跳板机访问。
nginx安装
这里使用docker-compose安装
# docker-compose.yml
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 docker-compose up -d
检查nginx支持stream模块
# 进入容器 docker exec -it [容器名] /bin/sh # 如果输出 with-stream,说明已支持。 # 若未输出,需重新编译nginx并添加 --with-stream 参数。 nginx -v 2>&1 | grep -o with-stream
配置nginx转发tcp流量
在nginx配置文件(如 /etc/nginx/nginx.conf)中添加 stream 块(与 http 块同级)
# nginx.conf
worker_processes 1;
error_log /etc/nginx/logs/error.log;
events {
worker_connections 1024;
}
stream {
include /etc/nginx/stream/*.conf;
}
# stream/ssh-01.conf
server {
listen 2201;
proxy_pass 192.168.2.78:22;
}
# stream/ssh-02.conf
server {
listen 2202;
proxy_pass 192.168.2.79:22;
}
重启nginx即可
大功告成,开始享用吧
切忌,该方式不适合生产使用,存在安全风险!
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论