Stop Hotlinking with Lighttpd

The technology behind the World Wide Web, the Hypertext Transfer Protocol (HTTP), does not make any distinction of types of links — all links are functionally equal. Resources may be located on any server at any location. Linking to an image stored on another site increases the bandwidth use of that site even though the site is not being viewed as intended. The complaint may be the loss of ad revenue or changing the perceived meaning through an unapproved context.

ADVERTISEMENTS

Here is easy and simple way to stop hotlinking :
Open lighttpd.conf file:
$ vi lighttpd.conf

#### stop image hijacking (anti-hotlinking)
$HTTP["referer"] =~ ".*BADDOMIN\.com.*" {
        url.access-deny = ( "" )
#      url.access-deny = ( "jpg", "png", "js", "jpeg", "gif" )
}

You can also enforce password protection:

$HTTP["referer"] =~ ".*BADDOMIN\.com.*" {
 auth.require = ( "/" =>
                   (        "method"  => "digest",
                            "realm"   => "Authorized users only",
                            "require" => "valid-user"
                   )
                 )
}

Restart lighttpd:
# service lighttpd restart

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
2 comments… add one
  • drivesoslow Apr 10, 2008 @ 15:54

    Wouldn’t be wiser to block all referrers by default and instead use a white list of those allowed?

    $HTTP[“referer”] =~ “*” {
    url.access-deny = ( “” )
    }
    $HTTP[“referer”] =~ “.*GOODDOMIN.com.*” {
    url.access-allow = ( “” )
    }

  • photos china Jun 13, 2008 @ 3:02

    I dont’t understand this line :
    url.access-deny = ( “” )

    and why the line
    # url.access-deny = ( “jpg”, “png”, “js”, “jpeg”, “gif” )

    is commented ? does it meen that every file called out of the domain are bloqued ?

Leave a Reply

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

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.