V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
luoo369
V2EX  ›  NGINX

>Nginx 缩略图 缓存到硬盘上 带后缀 nginx 如何配置

  •  1
     
  •   luoo369 · 2017-08-27 02:54:22 +08:00 · 2332 次点击
    这是一个创建于 2406 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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 语句

    1 条回复    2017-08-27 17:14:10 +08:00
    luoo369
        1
    luoo369  
    OP
       2017-08-27 17:14:10 +08:00
    ``` javascript


    location ~* (.*\.(jpg|gif|png))/w/(.*)/h/(.*)$ {
    root /home/wwwroot/$server_name/site_cache;
    set $width $3;
    set $height $4;
    set $image_path $1;
    set $demins "";
    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;
    }

    ```
    >搞定了,换了另外一种方法,访问形式是 xxx.jpg/w/240/h/180
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5922 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 02:36 · PVG 10:36 · LAX 19:36 · JFK 22:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.