nginx转发ssh服务

nginx stream模块简介

nginx从1.9.0开始,新增加了一个stream模块,用来实现四层协议的转发、代理或者负载均衡等。这完全就是抢HAproxy份额的节奏,鉴于nginx在7层负载均衡和web service上的成功,和nginx良好的框架,stream模块前景一片光明。

stream 模块编译

stream模块默认没有编译到nginx, 编译nginx时候 ./configure –with-stream 即可。

官网:http://nginx.org/en/docs/stream/ngx_stream_core_module.html

配置ssh内网转发

使用nginx做ssh转发可以连接到外网无法访问的内网主机

案例:

worker_processes 1;
events {
worker_connections 1024;
}
stream { #stream模块,就跟http模块一样
upstream ssh {
server 192.168.4.102:80;
}
server { #里面可以有多个监听服务,配置监听端口和代理的ip和端口就可以进行tcp代理了
listen 80;
proxy_pass ssh;
proxy_connect_timeout 1h;
proxy_timeout 1h;
}
}

测试:

[root@nginx-web ~]# ssh centos@192.168.4.115 -p 80
centos@192.168.4.115’s password:
Last login: Sat Dec 15 14:51:24 2018 from 192.168.4.110
[centos@ceshi ~]$ ip a

注意:
server里面不要使用location / 这种语句,否则报错

root@f7c53c3d6e67:/etc/nginx# nginx -t
2018/12/15 07:19:21 [emerg] 38#38: “location” directive is not allowed here in /etc/nginx/nginx.conf:14
nginx: [emerg] “location” directive is not allowed here in /etc/nginx/nginx.conf:14
nginx: configuration file /etc/nginx/nginx.conf test failed

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值