Virtual Hosts in Lighttpd using mod_evhost
Posted: July 1, 2009 | By: TJ | In Technology | No comments yet
I’ve seen a few different ways to set up virtual hosts in Lighttpd recently and tried a few different variations based on what I’ve found. The simplest solution for me was to use the mod_evhost module. The mod_evhost module essentially builds the document-root based on a pattern which contains wildcards. So, to begin, uncomment (or add if the module is not present) the mod_evhost from the server.modules section of the lighttpd.conf:
server.modules = ( ... "mod_evhost", ... )
Then, define the virtual host base directory and path pattern. Depending if you’ve installed from source, the var.basedir may be different:
var.basedir = "/var/www" evhost.path-pattern = var.basedir + "/%0/"
Save the lighttpd.conf and make sure that mod_evhost has been enabled:
$ lighty-enable-mod evhost
Before restarting Lighttpd, create your virtual host directories in /var/www:
$ mkdir /var/www/domain1.com $ mkdir /var/www/domain2.com
Once you’ve added content in the domain directories for domain1.com and domain2.com, you can restart Lighttpd:
$ /etc/init.d/lighttpd restart
You should now be serving virtual hosts for all domains located within /var/www. You can do some further tweaking to set up per domain access and error logs as well. Please check the official documentation for further information.





