2

In my nginx config, I have serveral location blocks, e.g.

location ~* /a { ..}
location ~* /b { ..}
location ~* /c { ..}

And I want to apply the expires header to all of above blocks, e.g.

location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ { 
    expires 1y;
}

Since in nginx, location blocks are exclusive to each other, so instead of repeating [1] the expires block in each of my locations above, are there better way to write the config?

[1]

location ~* /a {
    location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ ...
}

location ~* /b {
    location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ ...
}

location ~* /c {
    location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ ...
}
Howard
  • 2,135
  • 13
  • 48
  • 72

1 Answers1

3

You could set it for the server context instead of each location.

Then override, if you have any location blocks where it should not apply

Mathias R. Jessen
  • 25,161
  • 4
  • 63
  • 95