Trouble in Nginx hotlink protection

Solution 1:

You should ask this question on: https://serverfault.com/

My current site uses this:



## Stop Image and Document Hijacking, alow Google, MSN PicSearch
location ~* \.(png|gif|jpg|jpeg)$ {
        set $testref "";
        if ($http_referer !~ ^(http://mydomain.com|http://www.google|http://images.search.yahoo|http://www.bing|http://pictures.ask)){
           set $testref I;
        }
        if ($http_user_agent !~* (Googlebot|psbot|msnbot|Yahoo|Ask)) {
           set $testref "${testref}G";
        }
        if ($testref = IG){
           return 444;
        }
}


You can use only the first "if" part, the second is not to block Google and other image spiders. First part looks for referers from mydomain (and google, etc) and returns 444 in other cases. It can be replaced to return blank.gif image.