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

By BXTra | Tue, 02/15/2011 - 00:52

I have searched around how to prevent hotlink in Drupal when use with Nginx. A lot of website saying the same what to do. However, I have tried all of them but not even one of them that work. That was strange. I started to try more until this... I found the only method that work for me. Oh... one more thing... don't put them under "location" rule or it won't work. That took me half an hour to figure it out :(

Nginx Vhost configuration file - working config to protect hotlink

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

That's it. The code above will redirect all invalid domains that is access files directory into an image specified.

Source :
- http://wiki.nginx.org/NginxHttpRefererModule