How to protect against image hotlinking in Nginx

This short tutorial shows how I configured Nginx to protect against hotlinking of images used in my articles. Protecting against image hotlinking in Nginx is pretty simple, if you know what to do, or know how to google.

So if you don’t like my approach, go ahead and google “image hotlink protection in nginx” or something close to that.

In simple terms, hotlinking is stealing. That’s what it is. And the perpetrator is a thief. In slightly more technical terms, hotlinking is directly linking to images (usually) that reside on a website’s server, on your own. The recommended practice is to copy an image you are interested in and save it on your own server, then use it in your articles. I do it all the time, but some website owners are too lazy to bother.

Hotlinking is also know as inline linking, piggy-backing and leeching. I prefer that last one, because it conjures up the image of a parasite, which is what an hotlinker is. A lazy website owner is stealing bandwidth from another webmaster.

That was the problem I’ve been having with a publisher who has been reproducing my articles verbatim, hotlinking images in the process. The rest of this article shows how I configured Nginx to protect against the hotlinking.

I had two options: 1. Configure Nginx to refuse to serve images to the thief; 2. Serve a special image that tells the whole universe that the owner of the website they are viewing is a parasite. Because majority of the articles published on this site tend to be image-heavy, serving a special image that delivers a message will have the same impact on my bandwidth, so I chose option number 1.

In the site’s config file, I put this in the server{} context:

That works. Every image hotlinked from this website will just show the “alt” text on the thief’s website, with a lot of white space where the image is supposed to be. Any attempt to view the image will return a “403 Forbidden” error page. I’m pretty sure that’s the best configuration to use, but if you know of a better manner of setting it up, please post a comment.

The other option, which I did not use, is this:

That rewrite line can be tricky to pull off, so be careful if you want to consider using it. This screen shot shows the image I wanted to deliver. If the message and the color combination seems a bit harsh, that tells you how I feel about the offender. For now, a “403 Forbidden” will do.
Nginx hotlinking protection

Related Posts

Use GRUB-Customizer to give GRUB a prettier face on Linux Mint 17.1 I've been playing with the Cinnamon edition of Linux Mint 17.1 since it was released, and I've just gotta say that it's the best desktop distribution ...
How to password-protect GRUB Password-protecting the bootloader is one method you may employ to enhance the physical security profile of your computer. GRUB, the GRand Unified Boo...
Install NetworkManager on Hymera Open The network manager application that comes pre-installed on Hymera Open, a Debian-based, desktop-oriented GNU/Linux operating system, is Wicd. While ...
Dual-boot Windows 7 and Ubuntu 12.04 on a PC with UEFI board, SSD and HDD How to dual-boot Ubuntu 12.04 and Windows 7 and how to dual-boot Ubuntu 12.04 and Windows 7 on a computer with 2 hard drive provided step-by-step guid...
How to dual-boot BackTrack 5 R2 and Ubuntu 12.04 BackTrack Linux is now known as Kali Linux. You may read all Kali Linux articles and tutorial at http://linuxbsdos.com/category/kali-linux. Yet a...
Top 6 Linux and BSD graphical installation programs New users tend to flock to distributions with easy to use installation programs, that is, to distributions with graphical installers. Some people will...

We Recommend These Vendors and Free Offers

Launch an SSD VPS in Europe, USA, Asia & Australia on Vultr's KVM-based Cloud platform starting at $5:00/month (15 GB SSD, 768 MB of RAM).

Deploy an SSD Cloud server in 55 seconds on DigitalOcean. Built for developers and starting at $5:00/month (20 GB SSD, 512 MB of RAM).

Want to become an expert ethical hacker and penetration tester? Request your free video training course of Online Penetration Testing and Ethical Hacking

Whether you're new to Linux or are a Linux guru, you can learn a lot more about the Linux kernel by requesting your free ebook of Linux Kernel In A Nutshell.


Leave a Comment

Your email address will not be published. Required fields are marked *

*