Hosting Multiple
Websites or Namebased,IPbased Virtual hosts in Lighttpd
If you want to know how to install lighttpd check
here
Virtual hosting allows sharing a lighttpd web server so that you
can have multiple domains hosted on single web server. For
example:
=> www.test1.com
=> www.test2.com
=> www.test3.com etc
Lighttpd supports both Name-based and IP-based virtual hosts.
Let us see how to configure two sites for domain
www.test1.com
www.test3.com
First create a directory for each domain:
# mkdir -p /home/lighttpd/test1.com/http
# mkdir -p /home/lighttpd/test3.com/http
# chown lighttpd:ftpuser1 /home/lighttpd/test1.com/http
# chown lighttpd:ftpuser2 /home/lighttpd/test3.com/http
Replace ftpuser1 and 2 with actual ftp username.
Also create a log directory for each domain:
# mkdir /var/log/lighttpd/test1.com
# mkdir /var/log/lighttpd/test3.com
Only allow a web server to access our logs:
# chown -R lighttpd:lighttpd /var/log/lighttpd
Open lighttpd configuration file:
# vi /etc/lighttpd/lighttpd.conf
Add support for domain test1.com:
$HTTP[”host”] =~ “(^|\.)test1\.com$” {
server.document-root = “/home/lighttpd/test1.com/http”
server.errorlog = “/var/log/lighttpd/test1/error.log”
accesslog.filename = “/var/log/lighttpd/test1/access.log”
server.error-handler-404 = “/e404.php”
}
Add support for domain test3.com:
$HTTP[”host”] =~ “(^|\.)test3\.com$” {
server.document-root = “/home/lighttpd/test3.com/http”
server.errorlog = “/var/log/lighttpd/test3.com/error.log”
accesslog.filename = “/var/log/lighttpd/test3.com/access.log”
server.error-handler-404 = “/e404.php”
}
Where,
$HTTP[”host”] =~ “(^|\.)test3\.com$” : It will match request for
both www.test3.com and test3.com domain
server.document-root = “/home/lighttpd/test3.com/http” : Server
document root. You must set ftp/ssh user home directory to this
root only
server.errorlog = “/var/log/lighttpd/test3.com/error.log” :
Server access log file
accesslog.filename = “/var/log/lighttpd/test3.com/access.log”:
Server error log file
server.error-handler-404 = “/e404.php” : Web server error 404
handler file
Save the changes. Restart the server.
# /etc/init.d/lighttpd restart
Upload file(s) to respective web-root and test your
configuration with web browser.
Main Source of article can be found
here