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