nginx访问fastdfs和html,FastDFS+Nginx配置及报错处理

一、环境部署

1、准备工作

创建程序报下载目录:/home/Package

mkdir -pv/home/Package

下载程序包:

cd /home/Package

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz

wget http://zlib.net/zlib-1.2.8.tar.gz

wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz

wget http://iweb.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.15.tar.gz

wget http://nginx.org/download/nginx-1.9.14.tar.gz

2、关联包安装

1)yum安装系统lib包

yum -y installgcc automake autoconf libtool make

yum -y installgcc gcc-c++

yum -y installgc-devel

2)安装pcre

cd /home/Package/

tar fvxz pcre-8.37.tar.gz -C /usr/src/

cd /usr/src/pcre-8.37/

./configure

make && make install

3)安装zlib

cd /home/Package/

tar fvxz zlib-1.2.8.tar.gz -C /usr/src/

cd /usr/src/zlib-1.2.8/

./configure

make && make install

4)安装openssl

cd /home/Package/

tar fvxz openssl-1.0.1c.tar.gz -C /usr/src/

cd /usr/src/openssl-1.0.1c/

./configure

make && make instal

5)安装fastdfs-nginx-module

cd /home/Package/

tar fvxz fastdfs-nginx-module_v1.15.tar.gz -C /usr/src/

6)创建软链接

ln -s /usr/lib64/libfastcommon.so /usr/lib/

ln -s /usr/lib64/libfastcommon.so /usr/local/lib/

ln -s /usr/lib64/libfastcommon.so /usr/local/lib64/

ln -s /usr/lib64/libfdfsclient.so /usr/lib/

ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/

ln -s /usr/lib64/libfdfsclient.so /usr/local/lib64/

二、应用部署

1、Nginx

cd /home/Package/

tar fvxnginx-1.9.14.tar.gz -C /usr/src

cd/usr/src/nginx-1.9.14

./configure --prefix=/opt/nginx --user=www --group=www --sbin-path=/opt/nginx/sbin/nginx --pid-path=/opt/nginx/pid/nginx.pid --with-http_ssl_module --with-pcre=/usr/src/pcre-8.37 --with-zlib=/usr/src/zlib-1.2.8 --with-openssl=/usr/src/openssl-1.0.1i --add-module=/usr/src/fastdfs-nginx-module/src --with-http_image_filter_module --with-http_stub_status_module

make && make install

2、FastDFS

tar fvx FastDFS_v4.06.tar -C /usr/src/

cd/usr/src/FastDFS/

./make.sh

./make.shinstall

三、应用配置

1、配置nginx

ln -s/data/fdfs_store/data /usr/local/nginx/html/group1/M00

仅到需要进行动态缩略图显示的时候需要创建这个软连接

vim /usr/local/nginx/conf/nginx.conf

# 显示动态缩略图

location ~*/group1/M00/(w+)/(w+)/(.+).(png|jpg|gif)_(d+)x(d+).(png|jpg|gif) {

root"/usr/local/nginx/html/";

ngx_fastdfs_module;

set $iw"$5";

set $ih"$6";

image_filterresize $iw $ih;

image_filter_buffer2M;

try_files/group1/M00/$1/$2/$3.$4 /404.html;

}

# 显示原图

location /group1/M00 {

root"/usr/local/nginx/html/";

ngx_fastdfs_module;

}

2、配置FastDFS

mv /etc/fdfs/root/fdfs.bak

ln -s/usr/local/FastDFS/conf /etc/fdfs

vim /etc/fdfs/tracker.conf  (只列出需要修改的项目)

bind_addr=192.168.0.3

port=22122

base_path=/data/fastdfs

vim /etc/fdfs/storage.conf   (只列出需要修改的项目)

bind_addr=192.168.0.3

client_bind=true

port=23000

base_path=/data/fastdfs_storage

store_path0=/data/fastdfs_store

tracker_server=192.168.0.3:22122

http.server_port=80

vim /etc/fdfs/client.conf    (只列出需要修改的项目)

base_path=/data/fastdfs

tracker_server=192.168.0.3:22122

http.tracker_server_port=80

vim /etc/fdfs/mod_fastdfs.conf    (只列出需要修改的项目)

base_path=/data/fastdfs

tracker_server=192.168.0.3:22122

storage_server_port=23000

store_path0=/data/fastdfs_store

log_filename=/var/log/fdfs/mod_fdfs.log

附录一、问题及修复

1、[error] 30000#0: *1 open() "/usr/local/nginx/html/group1/M00/00/00/wKgAA1cLh12AI0kfAAAADzbdjmQ50_big.html"failed (2: No such file or directory), client: 192.168.0.181, server:localhost, request: "GET/group1/M00/00/00/wKgAA1cLh12AI0kfAAAADzbdjmQ50_big.html HTTP/1.1", host:"192.168.0.3"

原因:具体原因不明,可能是在做alias匹配的时候路径出现的问题

修复:修改nginx.conf中的location配置为:

location/group1/M00/ {

alias /home/FastDFS/data;

ngx_fastdfs_module;

}

2、ERROR - file: ../common/fdfs_global.c, line:52, the format of filename "group1/M00/00/00/wKgAA1cLh12AI0kfAAAADzbdjmQ50_big.html"is invalid

原因:nginx的fdfs的MOD里面默认没有开启url_have_group_name

修复:开启mod_fastdfs.conf文件中的url_have_group_name选项,后重启nginx

3、/usr/src/fastdfs-nginx-module/src/common.c:21:25:致命错误:fdfs_define.h:没有那个文件或目录

#include "fdfs_define.h"

^

编译中断。

原因:编译安装nginx的fastdfs插件的头文件没有找到,由于编译nginx时候系统会到/usr/local/include,而编译安装fastdfs-nginx-module时则默认保存在了/usr/include目录。

修复:ln -s /usr/include/fast* /usr/local/include/

4、nginx启动后error.log日志报错

ERROR - file:../storage/trunk_mgr/trunk_shared.c, line: 177, "No such file ordirectory" can't be accessed, error info: /data/fastdfs

ERROR - file:../storage/trunk_mgr/trunk_shared.c, line: 177, "No such file ordirectory" can't be accessed, error info: /data/fastdfs

ERROR - file:../storage/trunk_mgr/trunk_shared.c, line: 177, "No such file ordirectory" can't be accessed, error info: /data/fastdfs

ERROR - file:../storage/trunk_mgr/trunk_shared.c, line: 177, "No such file ordirectory" can't be accessed, error info: /data/fastdfs

原因:nginx的fdfs插件没有在/etc/fdfs目录中找到http.conf和mime.types。

修复:复制或者创建对应文件的软连接

cp/usr/local/FastDFS/conf/http.conf /etc/fdfs/

cp/usr/local/FastDFS/conf/mime.types /etc/fdfs/

5、页面访问动态缩略图返回415

原因:首先需要排除文件类型的问题,image_filter只支持jpg、git和png三种格式的图片文件,调用其他格式的图片文件会返回415。其次要确认设置的image_filter缓存是否小于上传的图片大小,如果小于同样会报415错误。如果排除以上两种可能性,那么出现的问题应该是没有在Nginx页面的DocumentRoot目录创建FastDFS数据存储的软连接。

修复:执行下列命令创建软连接:

# mkdir -pv/usr/local/nginx/html/group1

# ln -s /data/fastdfs_store/data/usr/local/nginx/html/group1/M00

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值