Kunaljain's Weblog

August 8, 2007

Lighttpd Name Based Virtual Hosting

Filed under: Lighttpd — Kunal Jain @ 08:54

Name Based Virtual Hosting

Suppose we have two websites http://www.this.com and http://www.that.com

First create a directory for each domain

# mkdir -p /home/www/vhost/this.com/http
# mkdir -p /home/www/vhost/that.com/http
# chown lighttpd:lighttpd /home/www/vhost/this.com/http
# chown lighttpd:lighttpd /home/www/vhost/that.com/http

Creating log directory for each domain

# mkdir -p /var/log/lighttpd/this.com
# mkdir -p /var/log/lighttpd/that.com
# chown -R lighttpd:lighttpd /var/log/lighttpd/this.com
# chown -R lighttpd:lighttpd /var/log/lighttpd/that.com

Opening lighttpd configuration file
# vi /etc/lighttpd/lighttpd.conf

Add the support for this.com
$HTTP[“host”] =~ “(^|\.)this.com” {
server.document-root = “/home/www/vhost/this.com/http”
server.errorlog = “/var/log/lighttpd/this.com/error.log”
accesslog.filename = “/var/log/lighttpd/this.com/access.log”
server.error-handler-404 = “/e404.php”
}

Add the support for that.com
$HTTP[“host”] =~ “(^|\.)that.com” {
server.document-root = “/home/www/vhost/that.com/http”
server.errorlog = “/var/log/lighttpd/that.com/error.log”
accesslog.filename = “/var/log/lighttpd/that.com/access.log”
server.error-handler-404 = “/e404.php”
}

where,

$HTTP[“host”] =~ “(^|\.)that.com” :- It will match for both http://www.that.com and that.com
server.document-root = “/home/www/vhost/that.com/http” :- Server Document Root
server.errorlog = “/var/log/lighttpd/that.com/error.log” :- Server Error Log File
accesslog.filename = “/var/log/lighttpd/that.com/access.log” :- Server Access Log File
server.error-handler-404 = “/e404.php” :- Web Server Error 404 Handler File

Restarting the lighttpd
# /etc/init.d/./lighttpd restart

**Upload files in the root document and test your configuration

Advertisements

1 Comment »

  1. very interesting. i’m adding in RSS Reader

    Comment by Melina — December 21, 2007 @ 05:41 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: