How to stop image Hotlinking on Nginx
Looking for a way to Stop Image Hotlinking on Nginx?
What is image hotlinking? Image Hotlinking is a very bad practice, it is used to steal bandwidth from your servers. What does this mean? It means someone creates a link to one of your images, but it is displayed on their websites. The result is you will end up paying more bandwidth transfer because of this. So, what you need is to secure your nginx server to block any hotlinking attempts.
Anti-hotlinking Nginx configuration:
Use a location directive inside your Nginx configuration file:
location ~ .(gif|png|jpe?g)$ { valid_referers none blocked mywebsite.com *.mywebsite.com; if ($invalid_referer) { return 403; } }
The first line shows the protected file extensions, if you have other extensions to add, just add a new pipe (“|”) with the new extension you want to protect.
valid_referers line contains the list of sites allowed to hotlink images, yours must be specified there, but if you have other websites you can allow them there.
You can also protect files from a specific directory. For example:
location /pictures/ { valid_referers none blocked mywebsite.com *.mywebsite.com; if ($invalid_referer) { return 403; } }
All done, now you know how to protect your website and directories from image hotlinking.
Popular search terms:
- https://www scalescale com/tips/nginx/how-to-stop-image-hotlinking-on-nginx/
- what is hot linking
- stop this image was hotlinked
- nginx scale images