Nginx image_filter

时间:2012-10-20 09:14:29

标签: static nginx amazon-s3 webserver image

我在S3上存储静态并使用nginx作为前端。对于从S3获取,我使用这种结构:

location / {
    try_files $uri @s3;
}

location @s3 {
    root /var/www/static.dev;
    proxy_pass https://bucket.s3-eu-west-1.amazonaws.com;
    proxy_store off; # for test purposes
    proxy_store_access all:rw;
    proxy_temp_path /dev/shm;
}

这项工作! 但我想生成拇指并使用此位置:

if ( $uri ~ ^/t/ ) {
    set $w 182;
    set $h 114;
}
if ( $uri ~ ^/m/ ) {
    set $w 640;
    set $h 1280;
}
if ( $uri ~ ^/l/ ) {
    set $w 1024;
    set $h 2048;
}

location ~ ^/(?:t|m|l)/(.*\.(?:jpg|gif|png))$ {
    rewrite ^/[t|m|l]+/(.*)$ /$1;
    image_filter crop $w $h;
}

但这不起作用,nginx返回415 Unsupported Media Type。 怎么了?

1 个答案:

答案 0 :(得分:0)

您可能想在url:t / m / l的每个部分使用location指令。

location ( ~ ^/t/ ) {
    set $w 182;
    set $h 114;
    root /;
    image_filter crop $w $h;
}