0

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";

}
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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