lighttpd forum lighty > Include file based on host domain?

Posted by Ib Board
on 03.09.2008 19:56
I'm trying to run a little light-weight server using Lighty that servers 
about half-a-dozen domains and subdomains. I'm okay with most of the 
config, except for one part where I'm potentially trying to get a bit 
too clever.

I've got a working config that does an include of site-specific config 
(some sites want certain rewrite rules, some want additional file 
extensions handled by PHP, etc, so a bit more than vhosts) using:

$HTTP["host"] =~ ... {
...
}
else $HTTP["host"] =~ ... {
...
}
else ...

but that seems a bit messy. What I'd like to do is just do:

include "lighttpd-" + host + ".conf"

and have the correct config loaded as necessary, but without the big 
conditional. I've tried matching host against .* and using %1, using 
server.name and using $HTTP["host"] directly, but none of them worked or 
compiled. Is this actually possible, or do I have to use the if/else 
structure?

Thanks.
Posted by Ib Board
on 04.09.2008 07:59
Never mind, I since realised that this isn't possible because of the 
difference between the config being read and includes being included at 
start time versus the conditionals being checked at request time.

I've got to test it yet, but my approximate new solution will be:

include_shell "cat /var/www/html/*/lighttpd-*.conf"

with each domain/subdomain having a folder in /var/www/html and its own 
lighttpd-[something].conf folder ([something] isn't necessary, but it's 
easier for differentiating them based on just file name) and each .conf 
file containing a block like:

$HOST["host"] == "example.com" {
...
}