04-FastDFS+Nginx对外提供静态资源访问

配置Nginx FastDFS实现文件服务器

在storage上安装

cd /home/software/FASTDFS/
tar -zxvf fastdfs-nginx-module-1.22.tar.gz
cd fastdfs-nginx-module-1.22/src/
vi config

修改配置

ngx_addon_name=ngx_http_fastdfs_module

if test -n "${ngx_module_link}"; then
    ngx_module_type=HTTP
    ngx_module_name=$ngx_addon_name
    ngx_module_incs="/usr/include"
    ngx_module_libs="-lfastcommon -lfdfsclient"
    ngx_module_srcs="$ngx_addon_dir/ngx_http_fastdfs_module.c"
    ngx_module_deps=
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
    . auto/module
else
    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"
    CORE_LIBS="$CORE_LIBS -lfastcommon -lfdfsclient"
    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/etc/fdfs/mod_fastdfs.conf\"'"
fi

继续部署

cp mod_fastdfs.conf /etc/fdfs/
cd /etc/fdfs/
cd /home/software/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=/home/software/FASTDFS/fastdfs-nginx-module-1.22/src

修改配置文件

cd /etc/fdfs/
mkdir /usr/local/fastdfs/tmp -p
vi mod_fastdfs.conf

配置文件

base_path=/usr/local/fastdfs/tmp
tracker_server=192.168.247.142:22122
group_name=dance
url_have_group_name = true
store_path0=/usr/local/fastdfs/storage

修改配置

cd /usr/local/nginx/
vi conf/nginx.conf

nginx配置文件

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       8888;
        server_name  localhost;
          # 为fastdfs的组名 + M00 虚拟路径
        location /dance/M00 {
            ngx_fastdfs_module;
        }
    }
}

启动Nginx

cd ../sbin/
[root@localhost sbin]# ./nginx
ngx_http_fastdfs_set pid=16247
[root@localhost sbin]#

测试图片访问

使用之前上传的图片的返回访问地址

http://192.168.247.143:8888/dance/M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063.jpg
http://192.168.247.143:8888/dance/M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063_big.jpg

访问成功图片

posted @ 2022-10-04 22:47  彼岸舞  阅读(66)  评论(0编辑  收藏  举报