I’m playing about with lighttpd on a small virtual private server. I two domains pointing to the server. I am using the latest version of lighttpd and mod_evhost on Ubuntu 8.10.
-
I’m trying to set up a rule such that if anyone requests domain.com or http://www.domain.com they get served from /webroot/domain.com/www/
-
Similarly, if anyone requests sub.domain.com they get served from /webroot/domain.com/sub/
-
If people requests fake.domain.com (where /webroot/domain.com/fake/ does not exist) I would like them served from /webroot/domain.com/www/
The third requirement isn’t quite so important, I can deal with people requesting subdomains that don’t exist being served from the server document root of /webroot/server.com/www/ even if they requested fake.domain.com
I’ve included the relevant parts of my lighttpd.conf file below:
server.document-root = '/webroot/server.com/www/' // regex to match sub.domain.com $HTTP['host'] =~ '\b[a-zA-Z]\w*\.\b[a-zA-Z]\w*\.\b[a-zA-Z]\w*' { evhost.path-pattern = '/webroot/%0/%3/' } // regex to match domain.com $HTTP['host'] =~ '\b[a-zA-Z]\w*\.\b[a-zA-Z]\w*' { evhost.path-pattern = '/webroot/%0/www/' }
So where am I going wrong? At the moment, all requests to *.domain.com and domain.com are being served from /webroot/domain.com/www/
I’d appreciate any help you guys could offer and if I’ve left anything relevant out please tell me!
Cheers, Rob
Your regexes seem to be a bit overdone.
Here is what I would use:
where:
To match only valid sub domains with fall back to ‘www’, you can use this: