FastDFS整合Nginx
浏览器访问FastDFS存储的图片需要通过Nginx访问
需要安装fastdfs-nginx-module、Nginx
安装fastdfs-nginx-module模块
(1)将fastdfs-nginx-module_v1.16.tar.gz上传到服务器,并进行解压
tar -zxvf fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/server/fastdfs
(2)进入/usr/local/server/fastdfsfastdfs-nginx-module/src目录下,修改配置文件config。此过程是必须的,否则会报错。
修改前的配置文件
ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/local/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
修改后的配置文件
ngx_addon_name=ngx_http_fastdfs_module
HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"
CORE_LIBS="$CORE_LIBS -L/usr/lib -lfastcommon -lfdfsclient"
CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
(3)将/usr/local/server/fastdfsfastdfs-nginx-module/src下的mod_fastdfs.conf拷贝到/etc/fdfs目录下
cp mod_fastdfs.conf /etc/fdfs
(4)修改mod_fastdfs.conf配置
base_path=/home/fastdfs
tracker_server=192.168.173.24:22122
#tracker_server=192.168.173.25:22122 #(多个tracker配置多行)
url_have_group_name=true #url中包含group名称
store_path0=/home/fdfs_storage #同理多个storage,配置多行
(5)将/usr/lib64下的libfdfsclient.so拷贝到/usr/lib目录下
cp /usr/lib64/libfdfsclient.so /usr/lib/
(6)创建client目录
mkdir -p /var/temp/nginx/client
安装Nginx
(1)将nginx-1.8.0.tar.gz上传到服务器,并进行解压
tar -zxvf nginx-1.8.0.tar.gz -C /usr/local/server/nginx
(2)安装nginx所需的环境,其中包括pcre、zlib、openssl
yum install pcre
yum install pcre-devel
yum install zlib
yum install zlib-devel
yum install openssl
yum install openssl-devel
(3)将fastdfs模块添加到Nginx中
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/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=/usr/local/server/fastdfs/fastdfs-nginx-module/src
(4)编译安装Nginx
make & make install
(5)配置nginx.conf
nginx默认安装在/usr/local/nginx下,进入/usr/local/nginx/conf目录下。
/usr/local/nginx/conf
vim nginx.conf
配置以下内容
pid /usr/local/nginx/logs/nginx.pid;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /group1/M00/ {
#root html;
#index index.html index.html;
root /home/fdfs_storage/data;
ngx_fastdfs_module;
}
}
(6)启动Nginx
cd /usr/local/nginx/sbin/
./nginx