valid_referers problem

Igor Sysoev igor at sysoev.ru
Sun Oct 24 11:50:36 MSD 2010


On Sat, Oct 23, 2010 at 10:06:27PM +0200, Todd HG wrote:

> I am using valid_referers to detect image hotlinking. Invalid referers
> are forwarded to the homepage, however, I have since changed the address
> for images from images.hollywoodgrind.com:9000 to
> www.hollywoodgrind.com.
> 
> The last line contains the rewrite rule 'rewrite ^
> http://www.hollywoodgrind.com$request_uri? permanent;', which would
> forward traffic going to images.hollywoodgrind.com:9000 to it's new
> exact location at www.hollywoodgrind.com.
> 
> What I'd like is for invalid traffic to be forwarded to the home page
> located at www.hollywoodgrind.com, but for valid traffic to be forwarded
> to the new url location for the image.
> 
> server {
>     listen       9000;
>     server_name  images.hollywoodgrind.com;
>     location /images {
>       valid_referers blocked ~\.google\. ~\.yahoo\. ~\.bing\. ~\.ask\.
> ~\.live\. ~\.googleusercontent.com\. www.hollywoodgrind.com
> feeds.hollywoodgrind.com/HollywoodGrind
> feeds2.feedburner.com/HollywoodGrind images.google.com 209.85.171.104
> google.com www.google.com yahoo.com my.yahoo.com
> feedproxy.google.com/HollywoodGrind images.search.yahoo.com live.com
> search.live.com 209.85.173.132 ask.com images.ask.com
> translate.googleusercontent.com googleusercontent.com bing.com;
>         if ($invalid_referer) {
>         rewrite  ^(.*)$  http://www.hollywoodgrind.com/;
>       }
>     rewrite ^ http://www.hollywoodgrind.com$request_uri? permanent;
>     }
> }

server {
    listen       9000;
    server_name  images.hollywoodgrind.com;

    location / {
        rewrite ^ http://www.hollywoodgrind.com$request_uri? permanent;
    }

    location /images {
        valid_referers  blocked
                        ~\.google\.
                        ~\.yahoo\.
                        ...
                        googleusercontent.com
                        bing.com
                        ;

        if ($invalid_referer) {
            rewrite  ^  http://www.hollywoodgrind.com/?;
        }

        rewrite ^ http://www.hollywoodgrind.com$request_uri? permanent;
    }
}


-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list