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

Category:

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 :(

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

Add new comment

Filtered HTML

  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <pre> <br /> <img> <center>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or class="OPTIONS" [title="the title"].
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.