We have lots of virtual hosting domains setup, using $host to point to
the correct root directory. This way we can add / subtract domains
without touching the nginx config.
This has been working perfectly for us, however we want to stop leeching
by checking the HTTP Referer.
Since the configuration is “virtual”, only the $host variable actually
“knows” the name of the vhost.
So we want to test to ensure that either $http_referer contains $host
(using an if statement), or using the HTTP Referer module with something
like this:
valid_referers none blocked $host;
Can you think of anyway to have nginx test two variables in this
fashion? Because of our setup, it is not possible to manually enter
these values in the config file, or manually setup a vhost for each
domain.
Thanks! Never even thought of doing that with just a reg exp that way -
I was able to adapt this and make it work!
It’s amazing how powerful nginx really is. We have fairly low traffic,
and some big boxes, so I’m not too concerned with the added performance
penalty / overhead of the if / rewrite module.
I know it is ugly, but the rewrite module does allow us to do some great
things at the server level, that we used to have to do in php.
Thanks again, and I’m going to brush up on my reg exp skills a little
tonight.
On Fri, Sep 18, 2009 at 10:28:50AM -0500, Resicow wrote:
valid_referers none blocked $host;
Can you think of anyway to have nginx test two variables in this
fashion? Because of our setup, it is not possible to manually enter
these values in the config file, or manually setup a vhost for each
domain.
As a workaround you may use something like:
set $blah "$host:$http_host";
if ($blah ~ "^([^:]+):\1$") {
return 403;
}
Maxim D.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.