Nginx resize function 2—resize file local storage

Make settings in the nginx.conf file in the /usr/local/nginx-1.6.2/conf directory, and set the following content:

File header added:

user  root;

For the server node of the file server, add the following content:

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+)/(.*)" ) {

            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;

 }

 

 

access:

original image

http://hostname/img/image4.jpg

Compressed image:

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

 

Image storage:

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

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326762762&siteId=291194637