Nginx: conditional "expires" directive

António P. P. Almeida appa at perusio.net
Tue Aug 16 18:30:29 UTC 2011


On 16 Ago 2011 19h18 WEST, nginx-forum at nginx.us wrote:

> Thanks. Now it's working. I guess my mistake was in additional
> quotes.

No. Your mistake was the expires 1y directive. The expires directive
"automagically" sets a Cache-Control header.

You can do it without variables, like this:

location ~* ^.+\.(?:jpe?g|gif|gz|zip|flv|rar|wmv|avi|css|swf|png|htc|ico|mpeg|mpg|txt|mp3|mov|js)$ {
   root /opt/lampp/htdocs/randevu/public;

   if ($arg_no_caching) {
      add_header Cache-Control no-cache;
      break; 
   }
   
   add_header Cache-Control max-age=31536000; # 1 year
} 

--- appa



More information about the nginx mailing list