Authentication

ModAuth Documentation

Rather than using htpasswd from an Apache install, there is an online htpasswd generator which can be used to create the htpasswd file.

Add mod_auth to /service/lighttpd/root/lighttpd.conf:

server.modules = (
  "mod_auth",
)

Create /var/websites/www.example.com/.htpasswd with the username and encrypted password from the online generator:

someuser:$apr1$A1NKq.Nf$emfdeavRayFSHYieX9EgP0

Edit your site's config file (/service/lighttpd/root/sites/www.example.com.conf) and enable the htpasswd backend:

## debugging
# 0 for off, 1 for 'auth-ok' messages, 2 for verbose debugging
auth.debug = 0
## type of backend - plain, htpasswd, ldap or htdigest
auth.backend = "htpasswd"
## for htpasswd
auth.backend.htpasswd.userfile = basedir + ".htpasswd"

Then add the authentication details. There's a couple ways of doing it:

  • Without regular expressions:
    auth.require = ( "/download/" =>
      (
        # method must be either basic or digest
        "method"  => "basic",
        "realm"   => "protected",
        "require" => "user=agent007|user=agent008"
      ),
      "/protected-folder/" =>
      (
        # limit access to server information
        "method"  => "basic",
        "realm"   => "protected",
        "require" => "valid-user"
      )
    )
  • or, using regular expressions:
    $HTTP["url"] =~ "^/download|^/protected-folder" {
      auth.require = ( "" =>
        (
          "method"  => "basic",
          "realm"   => "download archiv",
          "require" => "user=agent007|user=agent008"
        )
      )
    }
  • Restart lighttpd:

    svc -t /service/lighttpd

    Recent Updates

    • 1 year 12 months ago
    • 1 year 12 months ago
    • 2 years 2 days ago
      php 8.x
    • 2 years 3 days ago
      10.6.7
    • 2 years 5 days ago
      Drop Centos 5/6 stuff