Lighttpd virtualhost configuration ~ name-based virtual hosting
Q. How do I configure lighttpd web server as virtual host for serving multiple web site from a single public IP address (name-based virtual hosting)?
A. 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:
# mkdir -p /home/lighttpd/default/http
Next, open lighttpd.conf file:
# vi /etc/lighttpd/lighttpd.conf
Setup default document root:
server.document-root = "/home/lighttpd/default/http/"
Setup public IP address:
server.port = 80
server.bind = "72.12.5.10"
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:
# mkdir -p /home/lighttpd/domain1.com/http
# mkdir -p /home/lighttpd/domain1.com/logs
Open /etc/lighttpd/domain1.com.conf file:
# vi /etc/lighttpd/domain1.com.conf
Add following configuration directive:
$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:
# mkdir -p /home/lighttpd/domain2.net/http
# mkdir -p /home/lighttpd/domain2.net/logs
Open /etc/lighttpd/domain2.net.conf file:
# vi /etc/lighttpd/domain2.net.conf
Add following configuration directive:
$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:
# /etc/init.d/lighttpd restart
Make sure document root is owned by your web server user such as www-data or lighttpd:
# chown -R lighttpd:lighttpd /home/lighttpd/
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Linux / UNIX FAQ:
- FreeBSD Lighttpd fastcgi php configuration and installation
- Debian / Ubuntu Linux search package names with apt-cache command
- Lighttpd as you compiled without pcre support error and solution
- Apache name based VirtualHost example
- Fedora Core Linux chkconfig does not display service name
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!
Tags: address_ip, configure_lighttpd_virutualhost, default_document, document_root, domain_name, domain_names, host_names, ip_address, Lighttpd, public_ip, servers, virtual_host, virtual_hosting, webservers, webserver_ip, web_server ~ Last updated on: February 7, 2008



February 25th, 2008 at 11:36 pm
It is not a good idea to have document-root owned (or writable) by the webserver user. Then every error in scripts (php/cgi/whatever) can be misused very easily.
Only make document-root readable by the webserver. Add write permission only to dirs which really needed (uploads).