下載fastdfs-nginx-module
首先從Git上下載fastdfs-nginx-module源碼
sudo git clone https://github.com/happyfish100/fastdfs-nginx-module
修改fastdfs-nginx-module-master/src/config
文件中的兩行頭文件引用配置
ngx_module_incs="/usr/local/include /usr/include/fastdfs /usr/include/fastcommon"
CORE_INCS="$CORE_INCS /usr/local/include /usr/include/fastdfs /usr/include/fastcommon"
配置Nginx
下載Nginx壓縮包,解壓到任意目錄
首先安裝相關依賴(這裏以Ubuntu爲例,其它系統大同小異)
sudo apt-get install openssl libssl-dev
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install build-essential
編譯安裝Nginx,注意‘–add-module’的路徑爲fastdfs-nginx-module的src實際路徑
tar zxvf nginx-1.17.2.tar.gz
cd nginx-1.17.2
sudo ./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/local/nginx/nginx.pid \
--lock-path=/var/lock/nginx/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/home/feige/fastdfs/fastdfs-nginx-module/src/
sudo make && make install
啓動Nginx
- 複製mod_fastdfs.conf到/etc/fdfs/目錄
sudo cp /home/feige/fastdfs/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/mod_fastdfs.conf
- 修改/etc/fdfs/mod_fastdfs.conf
# connect timeout in seconds
# default value is 30s
connect_timeout=10
# FastDFS tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=192.168.175.129:22122
# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/home/feige/fastdfs/storage
- 複製mime.types到/etc/fdfs/目錄
sudo cp /home/feige/fastdfs/fastdfs-5.11/conf/mime.types /etc/fdfs/
- 修改Nginx配置
listen 8888 端口值是要與/etc/fdfs/storage.conf 中的 http.server_port=8888 相對應,因爲 http.server_port 默認爲 8888,如果想改成 80,則要對應修改過來
erver {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
- 啓動Nginx
sudo /usr/local/nginx/sbin/nginx
重啓命令如下:
sudo /usr/local/nginx/sbin/nginx -s reload
- 上傳文件訪問測試
參考我的另一篇博文FastDFS集羣環境搭建(一)單機FastDFS配置
sudo fdfs_upload_file /etc/fdfs/client.conf /home/feige/fastdfs/image/desktop.png
得到FastDFS存儲路徑group1/M00/00/00/wKivgV1BMqSAbc3tAADeqP7ACwc432.png
通過http://[Nginx`s IP]:8888/group1/M00/00/00/wKivgV1BMqSAbc3tAADeqP7ACwc432.png來訪問驗證,如果能夠訪問則表示配置成功
設置開機自啓動
如果是Ubuntu 18以上版本參考我的博文:Ubuntu 18.04設置開機自動啓動,然後編輯/etc/rc.local增加下面內容
# Start Nginx
sudo /usr/local/nginx/sbin/nginx
重啓後查看是否啓動成功sudo netstat -unltp|grep nginx