How can i set diffrent proxy cache time by diffrent uri

i tried to use like this

server {

set $cache_time 1d;

if ($request_uri = "/") {
    set $cache_time 3d;
}

if ($request_uri ~ "^/other") {
    set $cache_time 30d;
}

location / {
    try_files $uri @fetch;
}

location @fetch {
     proxy_cache_valid  200 301 302 $cache_time;
}

}

then i got error "invalid time value “$cache_time” in
/etc/nginx/xxx.conf

how can i fix this?

Posted at Nginx Forum:

Hello!

On Mon, Feb 15, 2016 at 05:11:40AM -0500, vps4 wrote:

if ($request_uri ~ "^/other") {

}

then i got error "invalid time value “$cache_time” in /etc/nginx/xxx.conf

how can i fix this?

Variables are not supported by the proxy_cache_valid directive.
Use different locations instead, e.g.:

location / {
    try_files $uri @fetch;
}

location /other {
    try_files $uri @fetch_other;
}

location @fetch {
    proxy_cache_valid 200 301 302 3d;
    ...
}

location @fetch_other {
    proxy_cache_valid 200 301 302 30d;
    ...
}


Maxim D.
http://nginx.org/