东湖之滨 发表于 2024-7-25 18:36:27

Nginx 代理sftp,访问Nginx服务器就间接访问sftp服务器

1、Nginx安装

(1)Linux安装Nginx

https://blog.csdn.net/wd520521/article/details/110129872 (2)Windows安装Nginx

https://blog.csdn.net/wd520521/article/details/136675643  2、检查Nginx是否有 stream模块

(1)Linux体系

#在nginx安装目录sbin目录下执行
./nginx -V https://i-blog.csdnimg.cn/blog_migrate/df6d3f45561ec80fdfcbeb6b608574b8.png
(2)Windows体系

#nginx解压目录下执行
nginx.exe -V https://i-blog.csdnimg.cn/blog_migrate/6cedab1eeb63e2bbc85ea863f42e4893.png
3、修改nginx设置文件 

(1)Linux体系

a、编辑设置文件

vim /usr/local/nginx/conf/nginx.conf b、在nginx.conf中 http模块上面增加下面设置

stream {

    upstream sftpurl{ #可自定义命名
      hash $remote_addr consistent;
      server sftp服务器的ip:sftp服务器的端口 max_fails=3 fail_timeout=60s;
    }      
    #sftp代理
    server {
      listen 21000;#随意设置本地的监听端口(需要在安全组中开放)
      proxy_connect_timeout 300s;
      proxy_timeout 300s;
      proxy_pass sftpurl;
    }      
} https://i-blog.csdnimg.cn/blog_migrate/e7a4e8483f36cf3b5e8bd9a37517127f.png
c、校验设置文件是否精确

./nginx -t nginx -t 假如提示有success 代表设置没题目。
(2)Windows体系 

a、编辑设置文件

打开设置文件nginx.conf
 b、在nginx.conf中 http模块上面增加下面设置

stream {

    upstream sftpurl{ #可自定义命名
      hash $remote_addr consistent;
      server sftp服务器的ip:sftp服务器的端口 max_fails=3 fail_timeout=60s;
    }      
    #sftp代理
    server {
      listen 21000;#随意设置本地的监听端口(需要在安全组中开放)
      proxy_connect_timeout 300s;
      proxy_timeout 300s;
      proxy_pass sftpurl;
    }      
} https://i-blog.csdnimg.cn/blog_migrate/e7a4e8483f36cf3b5e8bd9a37517127f.png
c、校验设置文件是否精确

nginx.exe -t nginx,exe -t 假如提示有success 代表设置没题目。
4、验证

在其他服务器利用stfp指定账号登陆,注意我们访问的是21000端口,而不是原来sftp的端口
sftp -P21000 sftp账号@代理服务器ip

sftp -P21000 xxx@xx.xx.xx.xx  https://i-blog.csdnimg.cn/blog_migrate/15df1804094826e337f5b6f47ff1ca20.png
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: Nginx 代理sftp,访问Nginx服务器就间接访问sftp服务器