前提:已成功安装fastdfs,详见centos7下安装fastdfs
参考:Centos7 安装FastDFS+nginx module
1.安装工具
yum -y install pcre-devel openssl openssl-devel
2.下载解压安装包
wget https://github.com/happyfish100/fastdfs-nginx-module/archive/master.zip
unzip master.zip
wget http://nginx.org/download/nginx-1.9.5.tar.gz
tar -zxv -f nginx-1.9.5.tar.gz
3.安装nginx
mv nginx-1.9.5 /usr/local/
cd /usr/local/nginx-1.9.5
./configure --add-module=/root/fdfs/fastdfs-nginx-module-master/src/ --prefix=/usr/local/nginx --user=nobody --group=nobody --with-http_gzip_static_module --with-http_gunzip_module
make
make install
注:此处需要添加fastdfs-nginx-module的源码
4.配置mod_fastdfs.conf
cp /root/fdfs/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/
mkdir /data/ngx
vi /etc/fdfs/mod_fastdfs.conf
修改下面四个参数:
# the base path to store log files
base_path=/data/ngx
# FastDFS tracker_server
tracker_server=192.168.153.130:22122
# 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=/data/fdfs/storage
# if the url / uri including the group name
url_have_group_name = true
5.添加http.conf,mime.types到/etc/fdfs
cd /root/fdfs/fastdfs-5.05/conf
cp http.conf mime.types /etc/fdfs
注:/root/fdfs/fastdfs-5.05为fastdfs的下载解压文件目录
参考Centos7 安装FastDFS+nginx module
6.修改nginx配置文件
vi /usr/local/nginx/conf/nginx.conf
配置内容如下:
location /group1/M00 {
#root指向数据根目录,即storage的store_path
root /data/fdfs/storage/data;
ngx_fastdfs_module;
}
7.启动nginx
启动:
/usr/local/nginx/sbin/nginx
验证:
curl http://localhost
查看错误信息
tail -f /usr/local/nginx/logs/error.log
重启:
/usr/local/nginx/sbin/nginx -s reload
8.测试
wget http://192.168.153.130/group1/M00/00/00/wKiZglauvkmANC2wAAAAPpWmuhI171_big.txt
成功下载文件到当前文件夹