nginx 代理 sftp转发流量
发布时间 2023-12-04 16:17:39作者: 怀里的懒猫
- 首先需要nginx安装有 stream模块,使用 nginx -V 查看下是否有 --with-stream,没有使用命令:
yum -y install nginx-all-modules.noarch
- 在nginx.conf中 http模块上面增加
stream {
upstream sftp{
hash $remote_addr consistent;
server 192.168.90.130:22 max_fails=3 fail_timeout=60s; #服务器的ip:sftp服务器的端口
}
#sftp代理
server {
listen 21002; #随意设置本地的监听端口(需要在安全组中开放)
proxy_connect_timeout 300s;
proxy_timeout 300s;
proxy_pass sftp;
}
}
- 重启nginx
nginx -s reload
- 访问:
命令:sftp -oPort=本地监听端口 sftp服务器的用户名@nginx的ip
输入密码:sftp服务器的密码,即可。