Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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)$ ...
}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.