码迷,mamicode.com
首页 > Web开发 > 详细

FasdDFS上增加ngx_cache_purge-2.3与http_image_filter_module模块实现剪裁缓存功能

时间:2020-04-21 15:12:58      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:master   nec   mp4   code   指定   img   arguments   local   erro   

说明:

1)目前在一台服务器上安装了2个nginx

2)现在需要在nginx2上增加剪裁跟缓存模块

3)增加模块为ngx_cache_purge-2.3与http_image_filter_module

 

1、使用/usr/local/nginx2/sbin/nginx -V
目前nginx模块如下:
configure arguments:
    --prefix=/usr/local/nginx2
    --user=www --group=www
    --with-http_ssl_module
    --with-http_flv_module
    --with-http_v2_module
    --with-http_mp4_module
    --with-http_realip_module
    --with-http_stub_status_module
    --with-http_gzip_static_module
    --add-module=/usr/local/fastdfs/fastdfs-nginx-module-master/src
    --http-client-body-temp-path=/data/nginx/tmp/nginx/client
    --http-proxy-temp-path=/data/nginx/tmp/nginx/proxy
    --http-fastcgi-temp-path=/data/nginx/tmp/nginx/fcgi
    --http-uwsgi-temp-path=/data/nginx/tmp/nginx/uwsgi
    --http-scgi-temp-path=/data/nginx/tmp/nginx/scgi
    --with-pcre

2、上传测试图片test1.jpg验证目前fast是否正常
fdfs_test /etc/fdfs/client.conf upload test1.jpg
example file url: http://IP:8080/G1/M00/00/0F/rBLaWF6ejQCAO0g2AAALHOyHsy4754_big.jpg

浏览器验证访问是否正常
http://IP:9989/G1/M00/00/0F/rBLaWF6ejQCAO0g2AAALHOyHsy4754_big.jpg

3、上传ngx_cache_purge-2.3到/usr/local/fastdfs/
解压
unzip ngx_cache_purge-2.3

4、上传nginx-1.10.0.tar.gz到/usr/local/fastdfs/
解压
tar -zxvf nginx-1.10.0.tar.gz -C /usr/local/nginx2

5、编译
cd /usr/local/nginx2/nginx-1.10.0/
安装需要依赖包
yum -y install gd-devel
需要重新编译的模块
./configure \
  --prefix=/usr/local/nginx2 \
  --user=www \
  --group=www \
  --with-http_sub_module \
  --with-http_ssl_module \
  --with-http_flv_module \
  --with-http_mp4_module \
  --with-threads \
  --with-http_realip_module \
  --with-http_stub_status_module \
  --with-http_gzip_static_module \
  --with-http_image_filter_module \
  --add-module=/usr/local/fastdfs/fastdfs-nginx-module-master/src \
  --add-module=/usr/local/fastdfs/ngx_cache_purge-2.3 \
  --http-client-body-temp-path=/data/nginx/tmp/nginx/client \
  --http-proxy-temp-path=/data/nginx/tmp/nginx/proxy \
  --http-fastcgi-temp-path=/data/nginx/tmp/nginx/fcgi \
  --http-uwsgi-temp-path=/data/nginx/tmp/nginx/uwsgi \
  --http-scgi-temp-path=/data/nginx/tmp/nginx/scgi \
  --with-pcre

正常返回信息:
  nginx path prefix: "/usr/local/nginx2"
  nginx binary file: "/usr/local/nginx2/sbin/nginx"
  nginx modules path: "/usr/local/nginx2/modules"
  nginx configuration prefix: "/usr/local/nginx2/conf"
  nginx configuration file: "/usr/local/nginx2/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx2/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx2/logs/error.log"
  nginx http access log file: "/usr/local/nginx2/logs/access.log"
  nginx http client request body temporary files: "/data/nginx/tmp/nginx/client"
  nginx http proxy temporary files: "/data/nginx/tmp/nginx/proxy"
  nginx http fastcgi temporary files: "/data/nginx/tmp/nginx/fcgi"
  nginx http uwsgi temporary files: "/data/nginx/tmp/nginx/uwsgi"
  nginx http scgi temporary files: "/data/nginx/tmp/nginx/scgi"

make

6、停止nginx2
/usr/local/nginx2/sbin/nginx -s stop

7、备份原来nginx
mv /usr/local/nginx2/sbin/nginx /usr/local/nginx2/sbin/nginx.bak

8、复制新编译的nginx到nginx2/sbin
cp /usr/local/nginx2/nginx-1.10.0/objs/nginx /usr/local/nginx2/sbin/

9、启动nginx
/usr/local/nginx2/sbin/nginx
(假如启动不起来的话指定配置文件启动/usr/local/nginx2/sbin/nginx -c /usr/local/nginx2/conf/nginx.conf)

10、nginx加入配置
cd /usr/local/nginx2/conf/

备份原来ngin.conf
cp nginx.conf nginx.conf.bak20200421

假如如下配置
vim nginx.conf

    #缓存
    proxy_connect_timeout 5;
    proxy_read_timeout 60;
    proxy_send_timeout 5;
    proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 128k;
    proxy_temp_path /home/temp_dir;
    proxy_cache_path /home/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g;


    location ~/s([0-9]+)x([0-9]+)fdfs/G[0-9]/(.+).(jpeg|Jpeg|jpg|gif|png) {

        #缓存

        proxy_cache cache_one;
        proxy_cache_valid 200 302 1h;
        proxy_cache_valid 301 1d;
        proxy_cache_valid any 1m;
        expires 30d;
        #剪裁
        set $w $1;
        set $h $2;
        if ($w != "0") {
            rewrite /s([0-9]+)x([0-9]+)fdfs/G1/(.+).(jpeg|Jpeg|jpg|gif|png)$ /G1/$3.$4 break;
        }
        image_filter resize $w $h;
        image_filter_buffer 20M;
        ngx_fastdfs_module;

        proxy_next_upstream http_502 http_504 http_404 error timeout invalid_header;
        proxy_cache_valid 200 304 12h;

    }

技术图片

11、检查启动nginx配置
./../sbin/nginx -t
./../sbin/nginx -s reload

12、浏览器原地址访问
http://IP:9989/G1/M00/00/0F/rBLaWF6ejQCAO0g2AAALHOyHsy4754_big.jpg

13、浏览器加入剪裁功能访问
http://IP:9989/s200x200fdfs/G1/M00/00/0F/rBLaWF6ejQCAO0g2AAALHOyHsy4754_big.jpg

FasdDFS上增加ngx_cache_purge-2.3与http_image_filter_module模块实现剪裁缓存功能

标签:master   nec   mp4   code   指定   img   arguments   local   erro   

原文地址:https://www.cnblogs.com/wangguod/p/12744499.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!