Setting cache parameters via if directives
Ryan Malayter
malayter at gmail.com
Fri Jan 28 18:55:37 MSK 2011
On Thu, Jan 27, 2011 at 11:08 PM, Jeff Mitchell <jeff at jefferai.org> wrote:
> location = / {
> if ($remote_addr = "1.2.3.4") {
> proxy_pass http://127.0.0.1:80;
> proxy_cache gitweb;
> proxy_cache_valid 200 20m;
> proxy_read_timeout 300;
> proxy_send_timeout 300;
> }
> proxy_pass http://127.0.0.1:80;
> proxy_cache gitweb;
> proxy_cache_valid 200 60m;
> proxy_cache_use_stale off;
> proxy_read_timeout 60;
> proxy_send_timeout 60;
> }
>
> Any help much appreciated.
I do something similar using the conditinal setting of variables
inside the if block to set Cache-Control values, perhaps you can use a
similar method to set the values of proxy_cache_valid. Since setting
variables is one of the few "safe" things to do inside an if block,
and most directives can take variables as agurments, it is generally
useful.
location / {
set $mycc = "private, max-age=0";
if ($foo = "bar") {
set $mycc = "public, max-age=3600"
}
proxy_pass http://backend;
add_header Cache-Control $mycc;
}
--
RPM
More information about the nginx
mailing list