Lighttpd with virtual hosts and subdomains
I set up this domain a while ago and I preferred to use lighttpd as web server. Why? Maybe for personal reasons: it was used on my NSLU2 and I found it pretty straightforward to configure.
At the beginning I set it up to setup both ctrl-alt-delete.ro and www.ctrl-alt-delete.ro to resolve to the same address. I did not need a(nother) subdomain, but as always in life, things change. Here I was scratching my head and wondering how to add the subdomain "test" to ctrl-alt-delete.ro while not changing anything in the way www.ctrl-alt-delete.ro and ctrl-alt-delete.ro worked.
I googled for a solution and came up on something like this:
$HTTP["host"] =~ "(.*?\.)?test\.ctrl-alt-delete\.ro" {
server.document-root = "/path/to/ctrl-alt-delete.ro/test/"
accesslog.filename = "/var/log/lighttpd/test.log"
}
Put that in your lighttpd.config file, create the folder "test" then you're ready. I tried but I was disappointed to see that it was not working. Oh well, I forgot to mention that I did not create a "CNAME record" on my DNS servers. Fixed. But it still did not work. I tried exact matching of the whole $HTTP["host"] but to no avail.
My config file specified the document root at "/path/to/ctrl-alt-delete.ro/blog" so it was very logical to put the "test" folder in there, which is correct indeed. But still with all the "A record" creation and the modification in the config file it was not working. The browser could not find the address.
So stop and re-think all. We're using virtual hosts, right? Right! We're creating a subdomain for a virtual host, right? Right! So what the fsck is server.document-root doing in matching the subdomain? We need this:
$HTTP["host"] =~ "(.*?\.)?test\.ctrl-alt-delete\.ro" {
simple-vhost.document-root = "/path/to/ctrl-alt-delete.ro/test/"
accesslog.filename = "/var/log/lighttpd/test.log"
}
Restart the lighttpd and there it is: your subdomain to a virtual host, other than the host-name itself or the www subdomain which both resolve to the same address.