一、场景说明
1、有N台服务器
2、公网IP只有一个或两个
3、其他服务器也想通过XShell或SecureCRT进行控制维护
二、开始前,需要知道
1、服务器已安装Nginx,可参考: Linux8 | 安装Nginx
2、了解Nginx常规配置
三、着手开干
1、Nginx配置增加tcp代理配置
配置文件: /usr/local/nginx/conf/nginx.conf
增加内容(与http同级):
stream { upstream ssh { server 192.168.0.2:22; } server { #里面可以有多个监听服务,配置监听端口和代理的ip和端口就可以进行tcp代理了。 listen 11682; proxy_pass ssh; proxy_connect_timeout 1h; proxy_timeout 1h; } }
示例图
2、重启服务即可
## 先停止
systemctl stop nginx
## 然后启动
systemctl start nginx
1)其实,如果没有stream模块,启动会报错;
2)需要重新配置,重新编译
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_sub_module --with-http_gzip_static_module --with-pcre --with-stream
make && make install
3)如果是通过yum install nginx安装的,稍微麻烦些;看下这位的操作