Linux系统nginx转发ftp服务的配置


nginx转发ftp服务的配置  

1.nginx要使用stream模块

FTP监听的是2121端口,nginx监听的是80端口,并转发ftp机器上的2121

修改配置文件nginx.conf   #代理 ftp服务

http{

  ...

}

stream{
  upstream ftp{
  hash $remote_addr consistent;
  server ftp的ip:端口;  # ftp网关的server IP
       }
  server {
  listen 80; #代理端口
  proxy_connect_timeout 300s;
  proxy_timeout 300s;
  proxy_pass ftp;

       }

}

 

#若是ftp使用被动模式传输,ftp server设置的端口范围60000-65535

#以下为新增数据端口,监听ftp服务器的数据端口

   upstream ftp1{
   hash $remote_addr consistent;
   server ftp的ip:60000;  //监听被动模式的端口1;
   }
   server {
    listen 60000;
    proxy_connect_timeout 10s;
    proxy_timeout 10s;
    proxy_pass ftp1;
   }
   upstream ftp2{
      hash $remote_addr consistent;
      server ftp的ip:60001;//监听被动模式的端口2;
   }
   server {
    listen 60001;
    proxy_connect_timeout 10s;
    proxy_timeout 10s;
    proxy_pass ftp2;
   }
        upstream ftp3{
      hash $remote_addr consistent;
   server ftp的ip:60002;   //监听被动模式的端口3;
   }
   server {
    listen 60002;
    proxy_connect_timeout 10s;
    proxy_timeout 10s;
    proxy_pass ftp3;
   }
}


亲测nginx 1.18版本,stream段要与HTTP段平行

不然会报错:error:nginx: [emerg] "server" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:1 nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

 2、验证测试FTP连接访问

说明:根据实际情况,开通外网访问FTP存储网关,简述测试方法

中途有些开防火墙等其他步骤省略,详细可期待下一篇~

内网测试

linux 上ftp命令能访问ftp

yum install ftp   #使用以下命令安装FTP Client

代理主机本地测试:a. ftp ftp的ip 2121   # ip:存储网关内网ip;

         b. ftp 本机ip 80

window上可以安装FileZilla软件访问ftp

ftp客户端连接类型需选被动模式

主机:填代理主机的EIP
用户名和密码:FTP Server创建的用户(oss下拉列表中的账号及密码)
端口:nginx配置的监听端口80 

 

 

参考链接:https://blog.csdn.net/qq_27127385/article/details/1036661

     https://docs.jdcloud.com/cn/storage-gateway/use-ftp

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM