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

    • PHP
      1 year 4 months ago
      PHP 7.4
    • 1 year 5 months ago
      MariaDB 10.4.12
    • 1 year 5 months ago
      Dovecot 2.3.10
    • 1 year 5 months ago
      CentOS 6 revisions
    • 1 year 5 months ago
      Copy of the revision from Wed, 08/22/2018 - 13:39.