Tag: Hotlink Protection

  • 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

    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