#### 前言
nginx从1.9.0开始,新增加了一个stream模块,用来实现四层协议的转发、代理或者负载均衡等
#### 准备工作
使用yum源安装nginx(详见:https://blog.youkuaiyun.com/weixin_42715225/article/details/105603410),默认自带stream模块
#### 配置nginx反向代理转发ssh服务
```
cat >> /etc/nginx/nginx.conf <<-EOF
stream {
upstream ssh {
server 192.168.150.95:22;
}
server {
listen 11888;
proxy_connect_timeout 3s;
proxy_timeout 5s;
proxy_pass ssh;
}
}
EOF
```
#### 测试nginx的配置是否正确
> nginx -t
```
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
```
#### 加载nginx
> nginx -s reload
#### 测试
> ssh root@192.168.150.95 -p 11888