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

    • 4 months 2 weeks ago
      1.27.2 update
    • 4 months 4 weeks ago
      Drupal 10/11 config
    • 4 months 4 weeks ago
    • PHP
      4 months 4 weeks ago
      PHP 8.3.11 and AlmaLinux
    • 5 months 4 hours ago
      New version of Pound