Setup lighttpd 1.4.18 Virtual Hosting in CentOS 5

What is a virtual hosting? It is a method that web servers such as lighttpd is use to host more than one domain name on the same server or on the same IP address. Virtual hosting can be accomplished in two methods such as ip-based virtual hosting and name-based virtual hosting. In this post, I will setup lighttpd 1.4.18 virtual hosting based on name-based virtual hosting to host domain1.com, www.domain1.com (both domain1.com and www.domain1.com is referring to the same website) and www2.domain2.com on 1 single web server.

1. Create each of the website directory like this: –

mkdir /srv/www/lighttpd/domain1.com
mkdir /srv/www/lighttpd/www2.domain2.com

2. Open lighttpd configuration file like this: –

vi /etc/lighttpd/lighttpd.conf

3. Add below text to support domain1.com and www.domain1.com at the end of file: –

$HTTP["host"] =~ "^(domain1.com|www.domain1.com)" {
server.document-root = "/srv/www/lighttpd/domain1.com"
}

4. Add below text to support www2.domain2.com at the end of file: –

$HTTP["host"] == "www2.domain2.com" {
server.document-root = "/srv/www/lighttpd/www2.domain2.com"
}

5. Save and exit file. Restart the lighttpd service like this: –

service lighttpd restart

6. Upload respective HTML files. Point your browser to the website and you will see the respective website.

If you found these helpful, please contribute to help:

Source: lighttpd