[HOW-TO] Prevent Hotlink in Drupal 6 + Nginx - 2nd Method

By BXTra | Tue, 02/22/2011 - 00:45

After tried [HOW-TO] Prevent Hotlink in Drupal 6 + Nginx for a few days. I found a second method which is very similar to the first method but the different is in valid_referers.

Nginx Vhost configuration file - Protect hotlink (regexp)

valid_referers none blocked server_names 
if ($invalid_referer) { 	
     rewrite ^/files.*\.(gif|jpg|jpeg|png|bmp)$ http://www.domainname.com/nohotlink.gif last;

Above code, you allow domainname.com to hotlink your images. You also allow google with any top level domain like google.com, google.de, www.google.com, images.google.com, etc. to hotlink your images. Bing is also allowed here.

Source :
- http://linuxsysadminblog.com/2009/08/using-wildcards-in-nginx-valid_referers/