Question on Rewrite / If statements
Maxim Dounin
mdounin at mdounin.ru
Fri Sep 18 19:46:28 MSD 2009
Hello!
On Fri, Sep 18, 2009 at 10:28:50AM -0500, Resicow wrote:
> Hi Igor,
>
> Thanks for your response.
>
> 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.
>
> Similar to the "Wildcard Subdomains in a Parent Folder" at
> http://wiki.nginx.org/NginxVirtualHostExample
>
> 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.
As a workaround you may use something like:
set $blah "$host:$http_host";
if ($blah ~ "^([^:]+):\1$") {
return 403;
}
Maxim Dounin
>
> Thanks,
>
> John
>
>
>
>
>
> Igor Sysoev wrote:
> >On Wed, Sep 16, 2009 at 08:03:26PM -0500, Resicow wrote:
> >
> >>Hello,
> >>
> >>I have learned that the http_referer module does *not* support variables.
> >>
> >>I am trying to work around this with if / rewrite statements,
> >>but may have run into the same issue.
> >>
> >>How can I make this work?
> >>
> >>set $myvar mydomain.com;
> >>if ($http_referer ~* $myvar) {
> >>do something
> >>}
> >>
> >>When I run that, it always returns false. However this works:
> >>
> >>if ($http_referer ~* mydomain.com) {
> >>do something
> >>}
> >>
> >>It appears that the if statement doesn't evaluate the variable.
> >>Is there anyway around this?
> >
> >Yes, "if" is ugly hack and it does not evaluate a right part of expression.
> >
> >What task do you want to resolve using $http_referer ?
> >
> >
>
>
More information about the nginx
mailing list