Lighttpd block wget useragent for specific urls

last updated in Categories Ask nixCraft, lighttpd, Linux, Security, Tips, Tuning, UNIX

One of regular reader asks a question:


My website powered by Lighttpd web server. I’d like to block Wget useragent for entire my site except for /downloads/ url section. How do I configure lighttpd?

You need to use $HTTP filed useragent and url combination. Just open your lighttpd.conf file and append code as follows.

Lighttpd block useragent wget configuration

# vi /etc/lighttpd/lighttpd.conf
Append config directive as follows:

$HTTP["useragent"] =~ "Wget" {
        $HTTP["url"] !~ "^/download($|/)" {
                url.access-deny = ( "" )


  • $HTTP[“useragent”] : Match on useragent i.e. Wget
  • $HTTP[“url”] : Match on url section such as /download/*. If there are nested blocks, this must be the most inner block.
  • =~ : Perl style regular expression match
  • !~ : Perl style regular expression not match

Just restart the webserver, enter:
# /etc/init.d/lighttpd restart

Now user can run wget on* urls but not on or


Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

5 comment

  1. This is pointless imo.
    Users will still be able to use wget on your whole domain if they use wget –user-agent ….

  2. # user-agent empty or made of any number of spaces rejected
    $HTTP[“useragent”] =~ “^ *$” {
    url.access-deny = ( “” )

    there’s a single space between ^ and *

    Have a question? Post it on our forum!