Hotlink protection in nginx

People hotlinking your content on their websites can be pretty annoying, especially if you don’t have a flat-fee traffic contract. The following will explain how to setup hotlink protection for nginx.

Add the following in your server {} context:

The above code will prevent hot-linking images (with the extention jpg, jpeg, png and gif) from your website.

You can also (instead of returning a 403 Forbidden) send another image, with this code (again, put it in the server{} context):

The above are just simple examples. You can add extentions to the examples (f.e. .flv, .mp4 etc) to protect even more files from your server.

Leave a Reply

Your email address will not be published.