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 ~(domainname.com|google.|bing.); 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/