Nginx: conditional "expires" directive

António P. P. Almeida appa at perusio.net
Tue Aug 16 11:33:24 UTC 2011


On 16 Ago 2011 12h14 WEST, nginx-forum at nginx.us wrote:

> I wanted to create if block for expires directive, but it's not
> allowed in if context.
>
> Like that:
>
> if($args ~ "no_caching=1") {
> expires      epoch;
> }
> Is it somehow possible to create this in any other way?
>
> I need nginx to change expire header to epoch when simple $_GET
> param no_cache=1 is in present.

You can try using the map directive:

http://wiki.nginx.org/HttpMapModule

map $args $caching_expires {
    default 30d;
    ~no_caching=1 epoch;
}


location /whatever {
   expires $caching_expires;      
}

I haven't tried it myself. 

--- appa



More information about the nginx mailing list