FastDFS與Nginx 整合
1.安裝FastDFS-Nginx-Module擴展
fastdfs-nginx-module可以重定向連接到源服務器取文件,避免客戶端由於複製延遲的問題,出現錯誤
cd /usr/local/src
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
2.安裝Nginx
路徑:/usr/local/src下
wget http://nginx.org/download/nginx-1.15.4.tar.gz #下載
tar -zxvf nginx-1.15.4.tar.gz #解壓
cd nginx-1.15.4/
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/ #進入nginx Nginx編譯環境設置 添加fastdfs-nginx-module模塊
make #編譯
make install #安裝
沒有wget的話需要安裝
sudo apt install wget
3.修改配置
3.1 修改mod_fastdfs.conf
vim /etc/fdfs/mod_fastdfs.conf
#修改配置
base_path=/home/FastDFS # 日誌和文件的根目錄 Storage
tracker_server=192.168.1.1:22122 # trackerker服務器IP和端口
url_have_group_name=true #url 中包含 group 名稱
store_path0=/home/fastdfs/fdfs_storage #指定文件存儲路徑
3.2 修改nginx.conf
vim /usr/local/nginx/conf/nginx.conf #配置nginx.config
# Nginx中添加如下配置,Storage服務器和Tracker服務器都需要配置Nginx
server {
listen 80; # 該端口爲storage.conf中的http.server_port相同
server_name localhost;
location /group1/M00 {
root /home/fastdfs/fdfs_storage/data;
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
4.啓動nginx
/usr/local/nginx/sbin/nginx # 自定義conf 可以通過 -c指定 如 ‐c /usr/local/nginx/conf/nginx‐fdfs.conf