Welcome! Log In Create A New Profile

Advanced

Hotlinking protection and try_files problem

October 31, 2014 11:37PM
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?
Subject Author Posted

Hotlinking protection and try_files problem

DamienR October 31, 2014 11:37PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 280
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready