Mapping host.domain.tld/path to /www/domain.tld/host/path in lighttpd

Some time ago, I needed to have several subdomains working, without having to define them in lighttpd. The domains had to be mapped like this: -> /var/www/ -> /var/www/
and so on.

Setting this up in lighttpd is actually VERY easy.
First, you should enable mod_evhost in /etc/lighttpd/lighttpd.conf by removing the # in front of it, in the server.modules section of the configuration file.

Next, you should add a section that handles the virtual host. For the domain specified above, I used this:

$HTTP["host"] =~ "\.domain\.com$" {
  server.errorlog = "/var/log/lighttpd/domain_error.log"
  accesslog.filename = "/var/log/lighttpd/domain_access.log",

The line that does the magic is of course evhost.path-pattern="/var/www/", where %3 is the subdomain.

Read more about mod_evhost here.

Written by Jannich Brendle man 09 november 2009 In How to

tags: hostinghowtolighttpdlinux

Related posts