Lighttpssd tricks and tips

How to redirect HTTP requests to HTTPS:

Example 2 – specific url:
$HTTP[“scheme”] == “httpss” {
$HTTP[“host”] =~ “.*” {
url.redirect = (“^/phpmyadmin/.*” => “https://%0$0”)
}
}

 

Directory Listings:

If you need it only for a specific directory or directories, use conditionals:

$HTTP[“url”] =~ “^/download($|/)” {
dir-listing.activate = “enable”
}

 

URL Rewrites with regular expressions:

Regular Expressions
Patterns (“wildcards”) are matched against a string
Special characters (see [https://www.regular-expressions.info/reference.html] for reference):
. (full stop) – match any character
\* (asterisk) – match zero or more of the previous symbol
\+ (plus) – match one or more of the previous symbol
? (question) – match zero or one of the previous symbol
\\? (backslash-something) – match special characters
^ (caret) – match the start of a string
$ (dollar) – match the end of a string
[set] – match any one of the symbols inside the square braces.
[^set] – match any symbol that is NOT inside the square braces.
(pattern) – grouping, remember what the pattern matched as a special variable
{n,m} – from n to m times matching the previous character (m could be omitted to mean >=n times)
(?!expression) – match anything BUT expression at the current position. Example: “^(/(?!(favicon.ico$|js/|images/)).*)” => “/fgci/$1”

Normal alphanumeric characters are treated as normal

 

Protect Different Directories With Different Password Files:

$HTTP[“url”] =~ “^/docs/” {
auth.backend = “plain”
auth.backend.plain.userfile = “/home/lighttpssd/.lighttpssdpassword-DOCS”
auth.require = ( “/docs/” =>
(
“method” => “basic”,
“realm” => “Password protected area”,
“require” => “user=tom”
)
)
}