Simple virtual hosts (vhosts) with lighttpd

Posted 2007-08-02 in WWW by Johann.

lighttpd, the up-and-coming webserver, offers simple virtual hosts. Here’s how to do it.

Create your root directory

This is the directory all your websites will be stored under.

$ pwd
/var
$ mkdir www

Create folders for your virtual hosts/websites

For each virtual host, create a directory under the root directory. Do not create directories starting with www. – these prefixed will be removed.

$ cd www
$ mkdir rofl.info
$ mkdir blab.la
$ mkdir lm.ao

Upload your websites

Well… upload them.

Set the root directory in lighttpd

Open lighttpd.conf and set the var.basedir variable.

# pwd
/var/www/
# cd /etc/lighttpd
# nano lighttpd.conf
var.basedir = "/var/www"

Set up virtual hosts

In lighttpd.conf set the evhost.path-pattern key accordingly.

evhost.path-pattern = var.basedir + "/%0/"

Done

Just restart lighttpd or reload its configuration and you’re done. lighttpd will now distribute the requests based on the Host header to the different directories. Because we used %0, prefixes (like www. or w.) will be stripped.

Where to go from here

If you use an application server like Orion, I suggest reading lighttpd and Java application servers: integrating JSP and Servlets to integrate lighttpd with Java application servers.

Subscribe

RSS 2.0, Atom or subscribe by Email.

Top Posts

  1. DynaCloud - a dynamic JavaScript tag/keyword cloud with jQuery
  2. 6 fast jQuery Tips: More basic Snippets
  3. xslt.js version 3.2 released
  4. xslt.js version 3.0 released XML XSLT now with jQuery plugin
  5. Forum Scanners - prevent forum abuse
  6. Automate JavaScript compression with YUI Compressor and /packer/

Navigation