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.

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

1 Answer 1

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.