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:
https://forum.nginx.org/read.php?2,264539,264539#msg-264539

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/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs