I am trying to block all requests which do not come from my own server.
A
quick read of the nginx wiki led me to the valid_referers directive. I
implemented it like:
I purposefully put not-my-domain.com instead of my-domain.com to make
sure a
403 status code was returned. Unfortunately, it is not. I wrote a simple
html file with an iframe that grabs a php page from the server from a
different domain. This should be returning a 403 code, but it works.
I purposefully put not-my-domain.com instead of my-domain.com to make sure
a 403 status code was returned. Unfortunately, it is not. I wrote a simple
html file with an iframe that grabs a php page from the server from a
different domain. This should be returning a 403 code, but it works.
Any ideas? Thanks.
Your request to php page is processed in “location ~.php” which do not
have any
referrer constraints.
valid_referers server_names not-my-domain.com;
if ($invalid_referer) {
return 403;
}
Into the php match block. Is there a way to do this without having the same
exact code copied into both location blocks?
You have to copy only
if ($invalid_referer) { return 403; }
The issue is that while the most nginx directive are declarative and
and can be easy inherted, the “if”, “rewrite”, “set”, and “return” are
imperative directives.