技术解析
location ~* ^/crop {
root /home/wwwroot/$server_name/site_cache;
set $width 240;
set $height 180;
set $dimens "";
if ($uri ~* "^/crop_(\d+)x(\d+)/(.*)" ) {
set $width $1;
set $height $2;
set $image_path $3;
set $demins "_$1x$2";
}
if ($uri ~* "^/crop/(.*)" ) {
set $image_path $1;
}
国外服务器 set $image_uri image_crop/$image_path?width=$width&height=$height;
if (!-f $request_filename) {
proxy_pass http://127.0.0.1/$image_uri;
break;
}
proxy_store /home/wwwroot/$server_name/site_cache/crop$demins/$image_path;
proxy_store_access user:rw group:rw all:r;
proxy_set_header Host $host;
expires 30d;
access_log off;
}
location /image_crop {
alias /home/wwwroot/$server_name/;
image_filter crop $arg_width $arg_height;
image_filter_jpeg_quality 75;
access_log off;
}
比如访问 http://pics.v2ex.com/wp-content/uploads/465484/1.jpg 的缩略图
使用下面这样的链接可以访问到默认的裁剪为 240x180 的缩略图并缓存到硬盘上
http://pics.v2ex.com/crop/wp-content/uploads/465484/1.jpg
如何这样带后缀访问缩略图 http://pics.v2ex.com/wp-content/uploads/465484/1.jpg_crop
用的七牛的缩略图函数 ,七牛的免费流量超限了,想用自己闲置的 vps 搭建一个图床,弄好了,但是缩略图不会配置,在网上扒了一些资料,搞不定,求大牛该如何添加一个 if 语句