#https://xx.com/a.jpg!80x80 匹配方式
location ~* /(.*)\/([\w]+)\.(jpg|png|jpeg|gif)!(\d+)x(\d+)$ {
if (-f $request_filename) {
break;
}
set $filepath $1;
set $filename "$2.$3";
set $thumb "$2_$4x$5.$3";
set $width $4;
set $height $5;
if (!-f $document_root/$filepath/$filename) {
return 404;
}
rewrite /(.*)\/([\w]+)\.(.*) /imgcache/$filepath/$2.$3;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1:$server_port/image-resize/$filepath/$filename?width=$width&height=$height;
break;
}
proxy_store $document_root/imgcache/$filepath/$thumb;
proxy_store_access user:rw group:rw all:r;
proxy_set_header Host $host;
}
# 匹配满足 /image_resize的URI,都是来自上面的location
location /image-resize {
rewrite /(image-resize)/(.*) /$2 break;
# 根据参数,resize 找到的图片
image_filter resize $arg_width $arg_height;
image_filter_jpeg_quality 75;
image_filter_buffer 10M;
# 禁止外网的访问,只允许本地访问
allow 127.0.0.0/8;
deny all;
}