nginx自动缩略图配置如下,直接搞定 fenxiao/upload文件夹的图片的缩略图自动生成
server下填写
location ~ /fenxiao/upload/(.+)_([0-9]+)x([0-9]+)\.(jpg|gif|png) {
#alias /upload/;
#root html;
#root /home/fenxiaosvn/;
#ngx_fastdfs_module;
set $w $2;
set $h $3;
if ($w != "0") {
proxy_pass http://127.0.0.1:8080/fenxiao/upload/$1.$4;
#rewrite fenxiao/upload/(.+)_([0-9]+)x([0-9]+)\.(jpg|gif|png)$ /fenxiao/upload/$1.$4 break;
}
if ($h != "0") {
proxy_pass http://127.0.0.1:8080/fenxiao/upload/$1.$4;
#rewrite fenxiao/upload/(.+)_([0-9]+)x([0-9]+)\.(jpg|gif|png)$ /fenxiao/upload/$1.$4 break;
}
#根据给定的长宽生成缩略图
image_filter resize $w $h;
#原图最大2M,要裁剪的图片超过2M返回415错误,需要调节参数image_filter_buffer
image_filter_buffer 5M;
add_header Nginx-Cache "$upstream_cache_status";
proxy_cache cache-temp-test;
proxy_cache_key $uri;
proxy_cache_valid 200 304 302 24h;
expires 20d;
#try_files group1/M00$1.$4 $1.jpg;
}
#location ~ /fenxiao/upload/(.+)\.?(.+){
#root html;
# root /home/fenxiaosvn/;
#alias /home/fenxiaosvn/fenxiao/upload;
#rewrite /(.*)$ /fenxiao/$1 redirect;
#}
location /{
# echo 'asdfasdf';
# root /fenxiao/;
# proxy_pass http://127.0.0.1:8080/fenxiao/;
rewrite /(.*)$ /fenxiao/$1 redirect;
}
location /fenxiao/{
#add_header Nginx-Cache "$upstream_cache_status";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/fenxiao/;
}
而启动缓存指需要http下:
proxy_cache_path /usr/local/openresty/nginx/proxy_cache_temp/ levels=2:2 keys_zone=cache-temp-test:50m inactive=7d max_size=5g use_temp_path=off;