Proxy_cache_valid inheritance

Hi,

I have a question about the proxy_cache_valid inheritance. I have the
following configuration:

http {

proxy_cache_valid 301 1h;
proxy_cache_valid 200 302 404 10m;
proxy_cache_valid any 1m;

server {
proxy_cache mycache;

location /test {
  proxy_pass http://$backend;
}

location /bar {
  proxy_pass http://$backend;
  proxy_cache_valid 5m;
}

location /foo {
  proxy_pass http://$backend;
  proxy_cache_valid 200, 301, 302, 404 5m;
}

}
}

In this conf:

  • /test will be cache with 1h for 301, 10m for 200/302/404 and 1m for
    the other types of response

How will be cahed requests to /foo ?

  • 200, 301, 302 = 5m, others won’t be cached ?
  • 200, 301, 302 = 5m, 404 = 10m (as set in http{}) and others will be
    cached for 1m (as set in http{}) ?

How will be cahed requests to /bar ?

  • 200, 301, 302, 404 = 5m, others won’t be cached ?
  • 200, 301, 302, 404 = 5m, others will be cached for 1m (as set in
    http{}) ?

I don’t know if setting proxy_cache_valid in location{} will totaly
overwritten proxy_cache_valid from http{} or just overwritten
specified values ?

Thx a lot
++ Jerome

Hi,

I don’t know if setting proxy_cache_valid in location{} will totaly
overwritten proxy_cache_valid from http{} or just overwritten
specified values ?

First one. If you’ve got at least one “proxy_cache_valid” directive in
your
location {} block then only options set in that location {} block will
be
used. This rule applies to most of the nginx settings.

Best regards,
Piotr S. < [email protected] >