Answer the question
In order to leave comments, you need to log in
How to properly use valid_referers in Nginx?
I decided to try to make protection from hotlink. The solution came out immediately:
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
valid_referers none blocked my.domain.ru www.my.domain.ru;
if ($invalid_referer) {
return 403;
}
expires max;
log_not_found off;
}
Answer the question
In order to leave comments, you need to log in
I found a solution, on one site in the comments. And it worked for me.
Remove none in the line valid_referers none blocked my.domain.ru www.my.domain.ru;
I would be grateful if someone could tell me the reason why it didn't work with none. Indeed, in the NGINX docs, an example is written with none (as a parameter for the absence of a Referer)?!
I will write for those who have the same problems as the topic starter
valid_referers none blocked server_names ~(\.yandex\.|\.google\.);
if ($invalid_referer) {
rewrite (.*)\.(jpg|jpeg|png|gif)$ [ссылка куда редиректить];
или
return 403; //блокируем
}
location ~ "[ссылка на вашем сайте]" {
try_files $uri $uri/ /index.php?$args;
valid_referers none blocked server_names ~(\.yandex\.|\.google\.);
if ($invalid_referer) { return 403; }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question