Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, if I want to split my prevent hotlink block from caching definition block, and put them in seperate .conf file to be included latter by main.conf, will nginx only match the first one?

location ~* \.(?:jpg|jpeg|gif|png|ico)$ {

        valid_referers none blocked somedomain.com;
        if ($invalid_referer) {
            return 403;
        }

}

...

location ~* \.(?:jpg|jpeg|gif|png|ico)$ {

        expires 1M;
        add_header Cache-Control "public";

}
share|improve this question

No, I don't believe this is possible due to the way that nginx processes the config file(s). When processing a request, nginx matches a single location block. So, where you have multiple location blocks with the same matching criteria, only the contents of the first block will be used. Check out the nginx phases docs:

http://wiki.nginx.org/HttpCoreModule#location

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.