Require Authentication For Multiple Directories in Lighttpd

By | 03/08/2009

I have a domain that I use to hold my notes, personal wiki, html versions of books and magazines, and other assorted resources.  Much of this I want to remain private so I’ve implemented Lighttpd access restrictions at the root of those directories.  I had a little bit of trouble this evening adding additional directories to my restriction list, so I thought I would make a note of it here.  Hopefully it’ll help anyone else running into similar trouble.


$HTTP["host"] =~ "domain.tld" {
auth.require = (
"/secret/" => (
"method"    => "basic",
"realm"     => "Password Protected Area",
"require"   => "valid-user",
),
"/private/" => (
"method"    => "basic",
"realm"     => "Password Protected Area",
"require"   => "valid-user",
)
)
}

The cause of my problem was the missing comma between the directory names. If you’re going to limit access to multiple directories in a list like this it needs to be a comma separated list.

4 thoughts on “Require Authentication For Multiple Directories in Lighttpd

    1. zelut Post author

      I did find a way to do multiple directories within a single rule. Below is an example:

      <code>
      $HTTP["host"] =~ "domain.tld" {
      auth.require = (
      "/private1/" => (
      "method" => "digest",
      "realm" => "Private Data",
      "require" => "user=username1|user=username2",
      ),
      "/private2/" => (
      "method" => "digest",
      "realm" => "Private Data",
      "require" => "user=user1",
      ),
      "/private3/" => (
      "method" => "digest",
      "realm" => "Private Data",
      "require" => "user=user1",
      )
      )
      }
      </code>

      Reply
  1. Julio Marroquin

    Thankkk you!

    Searched the web up and down until I finally found your article 🙂

    Never ever take it down! 😛

    Reply
  2. Jay

    You saved me. I was confused when lighttpd was crying about duplicate auth.require. I didn’t think you had to nest the multiple directories like that as it wasn’t listed in the documentation and all of the online guides and howtos. Can’t believe they neglected such a detail.

    Reply

Leave a Reply

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