nginx自动缩略图

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值