Setting cache parameters via if directives

Jeff Mitchell jeff at jefferai.org
Sat Jan 29 11:19:46 MSK 2011


On 01/28/2011 10:55 AM, Ryan Malayter wrote:
> 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;
> }

Great idea, thank you.

--Jeff



More information about the nginx mailing list