tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /home/sourcecode
nginx -v
nginx -V
--user=nginx --group=nginx --prefix=/usr/local/nginx --with-openssl=/home/sourcecode/openssl-1.1.1a --with-pcre=/home/sourcecode/pcre-8.42 --with-zlib=/home/sourcecode/zlib-1.2.11 --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-mail --with-mail_ssl_module --with-http_realip_module --with-http_stub_status_module --with-google_perftools_module --add-module=/home/sourcecode/ngx_cache_purge-2.3
进入到nginx源码目录(根据各自的nginx源码存放路径)
cd /home/sourcecode/nginx-1.14.2/
新建shell文件custom_configure.sh,
输入vi custom_configure.sh,然后按i 进入编辑模式,将之前的编译参数拷贝到文件中并加上fastdfs-nginx-module 模块,如下:
vi custom_configure.sh
#!/bin/bash
./configure \
--user=nginx --group=nginx --prefix=/usr/local/nginx --with-openssl=/home/sourcecode/openssl-1.1.1a --with-pcre=/home/sourcecode/pcre-8.42 --with-zlib=/home/sourcecode/zlib-1.2.11 --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-mail --with-mail_ssl_module --with-http_realip_module --with-http_stub_status_module --with-google_perftools_module --add-module=/home/sourcecode/ngx_cache_purge-2.3 --add-module=/home/sourcecode/fastdfs-nginx-module/src
按ESC键然后输入:wq保存custom_configure.sh文件
运行cat 命令查看是否有误
cat custom_configure.sh
运行shell脚本
sh custom_configure.sh
备份nginx的配置文件
cp /usr/local/nginx/sbin/nginx /home/nginx/nginx.bak
cp /usr/local/nginx/conf/nginx.conf /home/nginx/nginx.conf.bak
cp /usr/local/nginx/conf.d/nginx.conf /home/nginx/conf.d/nginx.conf.bak
在/home/sourcecode/nginx-1.14.2/目录执行安装命令
make && make install
出现如下报错:
/home/sourcecode/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c
In file included from /home/sourcecode/fastdfs-nginx-module/src/ngx_http_fastdfs_module.c:6:0:
/home/sourcecode/fastdfs-nginx-module/src/common.c:21:25: 致命错误:fdfs_define.h:没有那个文件或目录
修改fastdfs-nginx-module中的config文件
cd /home/sourcecode/fastdfs-nginx-module/src
vi config
将CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
改为CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
sh custom_configure.sh
编译安装nginx
make && make install
cd /usr/local/nginx/conf
vi nginx.conf
在server模块添加location /group1/M00
location / {
root /www/static/website;
index index.html index.htm;
}
location /group1/M00 {
ngx_fastdfs_module;
}
location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma|glb|ico)$ {
root /www/static/website;
expires 7d;
}
cp /home/sourcecode/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/
4.2 修改日志存储路径
vi /etc/fdfs/mod_fastdfs.conf
修改日志存储路径
base_path=/home/data/fastdfs/storage
tracker_server=192.168.98.22:22122
4.4 修改url_have_group_name为true
url_have_group_name = true
4.5 修改图片存储路径(必须要和storage.conf中的路径一致)
store_path0=/home/data/fastdfs/storage
4.6 复制http.conf、mime.types配置文件
cp /home/appuser/software/fastdfs-5.05/conf/http.conf /etc/fdfs
cp /home/appuser/software/fastdfs-5.05/conf/mime.types /etc/fdfs
/usr/local/nginx/sbin/nginx -s reload
service fdfs_trackerd restart
service fdfs_storaged restart
访问fastdfs中的图片
http://192.168.98.22/group1/M00/00/01/wKhiFlzKU_SAK70qAHItq7nb198241.jpg
遇到的问题
open() "/www/static/website/group1/M00/00/06/rBp0BV1qjh2AORYvAACsoDt2n2c775.png" failed (2: No such file or directory), client: 192.168.1.28, server: 192.168.98.22, request: "GET /group1/M00/00/06/rBp0BV1qjh2AORYvAACsoDt2n2c775.png HTTP/1.1"
,原因是匹配到了图片的location
location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma|glb|ico)$ {
root /www/static/website;
expires 7d;
}
location优先级为: = > ^~ > ~ 、~* > 常规字符串匹配
解决方法:将location修改为
location ^~/group1/M00 {
ngx_fastdfs_module;
}
参考
https://www.hyxcable.com/a/1190000018251300