Nginx Hotlink Protection

To block hotlink protection or bandwidth stealing, you can add the following to the server configuration of your website.

valid_referers yourdomain.tld www.yourdomain.tld;

if ($invalid_referer) {
    return 403;
}

If you need to allow hotlinks from a specific domain, you can edit the valid_referers line and add the URL. For allowing access without any referral, you can use “none” instead of the domain name. For example

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

Advertisement

location ~* \.(mp4|gif|png|jpg|jpeg|css|ico)$ {
    valid_referers  yourdomain.tld www.yourdomain.tld;
    if ($invalid_referer) {
       return 403;
    }
}
Add a comment

Leave a Reply

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

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement