1、首先需要nginx安装有 stream模块
a、使用 nginx -V 查看下是否有 --with-stream,没有使用命令:
yum -y install nginx-all-modules.noarch
2、在nginx.conf中 http模块上面增加
stream {
upstream sftp{ #可自定义命名
hash $remote_addr consistent;
server sftp服务器的ip:sftp服务器的端口 max_fails=3 fail_timeout=60s;
}
#sftp代理
server {
listen 21002;#随意设置本地的监听端口(需要在安全组中开放)
proxy_connect_timeout 300s;
proxy_timeout 300s;
proxy_pass sftp;
}
}
3、校验:nginx -t 如果提示有success 代表配置没问题。
4、如何访问:
命令:sftp -oPort=本地监听端口 sftp服务器的用户名@nginx的ip
输入密码:sftp服务器的密码,即可。