Lighttpd

Lighttpd virtualhost configuration/name-based virtual hosting
Virtual hosting is a method that servers such as webservers use to host more than one domain name on the same server, sometimes on the same IP address.

There are two basic methods of accomplishing virtual hosting. (A) name-based virtual hosting : You use multiple host names for the same webserver IP address. For example domain nixcraft.com and theos.in uses same IP address called 65.111.211.111.

(B) ) IIP address / ip-based virtual hosting

How do I configure Lighttpd for name-based virtual hosting?
Let us say your setup is as follows:

Public IP address: 72.12.5.10 Domain names: domain1.com and domain2.net Default Document Root: /home/lighttpd/default/http Default Document Root for domain1.com: /home/lighttpd/domain1.com/http Default Document Root for domain2.net: /home/lighttpd/domain2.net/http

First, create required directories: Next, open lighttpd.conf file: Setup default document root: server.document-root = "/home/lighttpd/default/http/" Setup public IP address: server.port = 80 server.bind = "72.12.5.10"
 * 1) mkdir -p /home/lighttpd/default/http
 * 1) vi /etc/lighttpd/lighttpd.conf

At the bottom of the file, add: include "domain1.com.conf" include "domain2.net.conf"

Save and close the file. Create domain1.com virtual host configuration

Create required directories:
 * 1) mkdir -p /home/lighttpd/domain1.com/http
 * 2) mkdir -p /home/lighttpd/domain1.com/logs

Open /etc/lighttpd/domain1.com.conf file: Add following configuration directive:
 * 1) vi /etc/lighttpd/domain1.com.conf

$HTTP["host"] =~ "domain1\.com" { server.document-root = "/home/lighttpd/domain1.com/http" accesslog.filename        = "/home/lighttpd/domain1.com/logs/access.log" }

Save and close the file. Create domain2.net virtual host configuration

Create required directories:
 * 1) mkdir -p /home/lighttpd/domain2.net/http
 * 2) mkdir -p /home/lighttpd/domain2.net/logs

Open /etc/lighttpd/domain2.net.conf file: Add following configuration directive:
 * 1) vi /etc/lighttpd/domain2.net.conf

$HTTP["host"] =~ "domain2\.net" { server.document-root = "/home/lighttpd/domain2.net/http" accesslog.filename        = "/home/lighttpd/domain2.net/logs/access.log" }

Save and close the file.

Restart the lighttpd web server:
 * 1) /etc/init.d/lighttpd restart

Make sure document root is owned by your web server user such as www-data or lighttpd:
 * 1) chown -R lighttpd:lighttpd /home/lighttpd/

by Vivek Gite on October 18, 2007 · 1 comment