nginx resize功能2—resize文件本地存储

在/usr/local/nginx-1.6.2/conf目录下的nginx.conf文件中进行设置,设置如下内容:

文件头增加:

user  root;

为文件服务器的server节点,增加如下内容:

location ~* ^/img/resize/w_(\d+)/h_(\d+)/(.*)$ {  

      root /usr/local/nginx-1.6.2/html/img/cache;

      set $width 150;

      set $height 100;

      set $dimens "";

      if ($uri ~* "^/img/resize/w_(\d+)/h_(\d+)/(.*)" ) {

扫描二维码关注公众号,回复: 290305 查看本文章

            set $width $1;

            set $height $2;

            set $image_path $3;

            set $demins "_$1x$2";

      }

      set $image_uri /img/resize/$image_path?width=$width&height=$height;

      if (!-f $request_filename) {

            proxy_pass http://127.0.0.1/$image_uri;

            break;

      }

      proxy_store /usr/local/nginx-1.6.2/html/img/cache/resize$demins/$image_path;

      proxy_store_access all:rw;

      proxy_set_header Host $host;

      expires   1d;

      access_log off; 

}     

location /img/resize/{  

      alias /usr/local/nginx-1.6.2/html/img/;

      image_filter resize $arg_width $arg_height;

      image_filter_buffer 50M;

      access_log off;

 }

访问:

原图

http://hostname/img/image4.jpg

压缩图:

http://hostname/img/resize/w_120/h_129/image4.jpg

图片存储:

/usr/local/nginx-1.6.2/html/img/cache/resize_120x129/image4.jpg

猜你喜欢

转载自alex-yang-xiansoftware-com.iteye.com/blog/2373350