Nginx Browser Caching using HTTP Headers outside server/location block

Posted by Danny O'Sullivan on Pro Webmasters See other posts from Pro Webmasters or by Danny O'Sullivan
Published on 2013-06-14T17:18:06Z Indexed on 2013/11/13 16:18 UTC
Read the original article Hit count: 532

Filed under:
|
|

I am having difficulty setting the HTTP expires headers for Nginx outside of specific server (and then location) blocks. What I want is to something like the following:

location ~* \.(png|jpg|jpeg|gif|ico)$ {
    expires 1y;
}

But not have to repeat it in every single server block, because I am hosting a large number of sites. I can put it in every server block, but it's not very DRY.

If I try to put that into an HTTP block or outside of all other blocks, I get "location directive is not allowed here." It seems I have to put it into a server block, and I have a different server block for every virtual host.

Any help/clarification would be appreciated.

© Pro Webmasters or respective owner

Related posts about cache

Related posts about http-headers