Welcome! Log In Create A New Profile

Advanced

Re: how can i set diffrent proxy cache time by diffrent uri

Maxim Dounin
February 15, 2016 08:22AM
Hello!

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

> 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?

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 Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

how can i set diffrent proxy cache time by diffrent uri

vps4 February 15, 2016 05:11AM

Re: how can i set diffrent proxy cache time by diffrent uri

Maxim Dounin February 15, 2016 08:22AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 121
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready