I have this config

location /mirror/files {
    valid_referers none server_names example.com *.example.com;
         if ($invalid_referer) {
            rewrite ^/(.*)$ http://example.com/;
    index index.php;

If I visit a link http://example.com/mirror/files/test.zip with referer that start with "http://example2.com" I can access the file. How to make it work? UPDATE: I can see from the server logs the referer is sent so it's not empty.


OK the reason was that I was using a localhost referer (my local development env) and apparently nginx treats that if it's coming from the local server which is silly since the IP should be checked if it's local as well.

Solution is either use real domains as referers or set your local server with another severname than localhost.

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.