在编译Nginx时,记得增加http_image_filter模块,然后在server区域加入如下代码即可。
如果你懒得编译这个模块,也可以下载我编译好的Webox直接安装。

#生成缩略图(等比例)
#http://www.anrip.com/expamle/test.jpg?r128x128
if ($args ~ ^r\d+x\d+$) {
    rewrite ^(.+)$ $1/$args? last;
}
location ~* \.(gif|png|jpg|jpeg)/r(\d+)x(\d+)$ {
    rewrite ^(.+)/r(\d+)x(\d+)$ $1 break;
    image_filter resize  $2 $3;
    image_filter_buffer  10M;
}
#生成裁切图片(固定高宽)
#http://www.anrip.com/expamle/test.jpg?c128x128
if ($args ~ ^c\d+x\d+$) {
    rewrite ^(.+)$ $1/$args? last;
}
location ~* \.(gif|png|jpg|jpeg)/c(\d+)x(\d+)$ {
    rewrite ^(.+)/c(\d+)x(\d+)$ $1 break;
    image_filter crop  $2 $3;
    image_filter_buffer  10M;
}

标签: nginx

添加新评论