Nginx Hotlink Protection
To block hotlink protection or bandwidth stealing, you can add the following to the server configuration of your website.
1 2 3 4 5 |
valid_referers yourdomain.tld www.yourdomain.tld; if ($invalid_referer) { return 403; } |
If you need to allow hotlink from a specific domain, you can edit the valid_referers line and add the url. For allowing access with out any referral, you can use “none” instead of the domain name. For example
1 |
valid_referers none yourdomain.tld www.yourdomain.tld; |
If you only want to limit access to images and videos, you can put the above code in a location block like
1 2 3 4 5 6 |
location ~* \.(mp4|gif|png|jpg|jpeg|css|ico)$ { valid_referers yourdomain.tld www.yourdomain.tld; if ($invalid_referer) { return 403; } } |
Example
https://gist.github.com/serverok/e7e8e275a7ec3b69e19252edfed483e2
See Nginx