Hotlinking protection and try_files problem

DamienR nginx-forum at nginx.us
Sat Nov 1 03:37:19 UTC 2014


Hi, I'm having some trouble getting hotlinking protection working with nginx
and xenforo forum software.

Currently I have;


server {
    listen   80;
    ...

    location / {
    try_files $uri $uri/ /index.php?$uri&$args;
    }

    location ~ \.php$ {
    ....
    }

    location ~* ([0-9a-zA-Z])+-(png|jpg|jpeg|gif)[.]([0-9]+)/$ {
    valid_referers server_names blocked *.mydomain.com;
    if ($invalid_referer) {
    rewrite ^(.*)$ url/to/leech.gif break;
    }
  }
}

This will 404 image attachments, as the developers put it; 

"Nginx only matches one location block per request "attempt" (try_files
retries the attempt with the new URL). So basically, the try_files block
isn't being hit after your referrer block... block. I don't know what the
best practice is here unfortunately".

domain.com/attachments/someimage-jpg.3/

404's with the error;

.../attachments/someimage-jpg.3/index.html" is not found (2: No such file or
directory), client: xxx.xxx.x.xx, server: domain.com, request: "GET
/attachments/someimage-jpg.3/ HTTP/1.1", host: "domain.com", referrer:
"http://domain.com/threads/thread.1/"

It's adding /index.html in the backend processing. Any ideas how I can get
this to work?

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,254500,254500#msg-254500



More information about the nginx mailing list