一耀里、環(huán)境規(guī)劃
節(jié)點(diǎn) | IP地址 | 節(jié)點(diǎn)系統(tǒng) |
---|---|---|
nginx | 172.16.102.37 | Centos7.9.2009 |
說明:FTP使用TCP協(xié)議蜈缤,使用stream模塊轉(zhuǎn)發(fā)數(shù)據(jù)。
二冯挎、開始配置
2.1底哥、配置nginx入口。
- 備份nginx主文件:/etc/nginx/nginx.conf
- 修改nginx配置文件:/etc/nginx/nginx.conf
- nginx主配置文件添加stream模塊房官。
- nginx主配置文件完整如下
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
stream {
log_format proxy '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
access_log /var/log/nginx/tcp_access.log proxy;
error_log /var/log/nginx/tcp_error.log;
#包含額外stream配置文件
include /etc/nginx/stream.d/*.conf;
}
- stream模塊添加了子配置目錄
- 創(chuàng)建子配置目錄文件趾徽,實(shí)現(xiàn)真正的業(yè)務(wù)邏輯。
- vim /etc/nginx/stream.d/ftp.conf
upstream ftp {
server 172.16.102.37:8021;
server 172.16.102.38:8021;
server 172.16.102.39:8021;
}
server {
listen 8081;
proxy_pass ftp;
proxy_timeout 3m;
proxy_next_upstream on;
proxy_next_upstream_tries 3;
}
2.2翰守、nginx重啟
重新加載配置
systemctl daemon-reload
重啟nginx
systemctl stop nginx
systemctl start nginx
2.3孵奶、查看nginx監(jiān)聽。8081端口已監(jiān)聽蜡峰。
image.png
2.4了袁、測(cè)試ftp客戶端。
找一臺(tái)服務(wù)器安裝ftp客戶端:172.16.1.39
yum -y install ftp
通過nginx登錄遠(yuǎn)程ftp服務(wù)端
ftp 127.16.102.37 8081
>>輸入賬號(hào): xxxxxx
>>輸入密碼:xxxxx
image.png
2.5湿颅、nginx配置后载绿,測(cè)試上傳下載
- 客戶端登錄ftp。
- 使用put命令上傳油航,可以顯示成功卢鹦。
image.png
- 下載測(cè)試
-
下面2張圖可以確認(rèn),使用get下載文件正常劝堪。
image.png
image.png
2.6冀自、到此,ftp配置nginx轉(zhuǎn)發(fā)后秒啦,通過nginx入口熬粗,可以正常上傳、下載數(shù)據(jù)余境。