Lighttpd: How do I use more than two IP address (bind) for virtual hosting?

by on July 11, 2006 · 7 comments· LAST UPDATED December 1, 2007

in , ,

Lighttpd logo

Virtual hosting is nothing but the provision of Web server hosting services so that a company (or individual) doesn't have to purchase and maintain its own Web server and connections to the Internet.

Lighttpd does support or allows you to bind more than two IP address simultaneously using $SERVER["socket"]..

For example,
IP # 1: 192.168.1.1 domain nixcraft.com
IP # 2: 192.168.1.2 domain theos.in

Open lighttpd.conf file:
# vi /etc/lighttpd/lighttpd.conf

First use server.bind and server.port to setup 192.168.1.1 IP
server.port = 80
server.bind = "192.168.1.1"

Now define nixcraft.com virtual host:
$HTTP["host"] == "www.nixcraft.com" {
server.document-root = "/home/lighttpd/nixcraft.com/http"
server.errorlog = "/var/log/lighttpd/nixcraft.com/error.log"
accesslog.filename = "/var/log/lighttpd/nixcraft.com/access.log"
}

Next use $SERVER["socket"] to bind 192.168.1.2:80 for theos.in domain:
$SERVER["socket"] == "192.168.1.2:80" {
server.document-root = "/home/lighttpd/theos.in/http"
server.errorlog = "/var/log/lighttpd/theos.in/error.log"
accesslog.filename = "/var/log/lighttpd/theos.in/access.log"
}
Save and close config file. Restart the lighttpd:
# /etc/init.d/lighttpd restart

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 7 comments… read them below or add one }

1 slav0nic December 1, 2007 at 6:34 pm

good, but if i has 2 domain on 192.168.1.2 ? =)

Reply

2 nixCraft December 1, 2007 at 8:16 pm

Go here. If you have more question use our forum.

Reply

3 Kathleen J Caunter January 12, 2008 at 11:34 pm

i am confused on how to fix this problem everytime i try to sumit info on a forum it states website cant display this page i dont understand what to do i am ok with computers but this problem fixer is confusing to me caan you help me please as i have important info to sumit on this forum about my custom show car and it was suppose to be sumitted by thiss weekend sun night the latest caan you please put it in simple terms i would apprecciate your help so much Kathy

Reply

4 Nazz April 30, 2008 at 7:49 am

I’m trying to use lighttpd with virtual hosting and different ssl certs for each host. I have one ip that is external and one virtual ip on the same machine.

I have both of the ips set, but since they are the same server, I always get the same certificate. Adding a host check doesn’t work and when I do that neither site works via ssl.

$SERVER[“socket”] == “10.0.0.1:443″ {

$HTTP[“host”] =~ “www.woohoo.com” {
ssl.engine = “enable”
ssl.pemfile = var.confdir + “/www. woohoo.com.ext.pem”
ssl.ca-file = var.confdir + “/gd_intermediate.crt”
server.name = var.confdir + “/www.woohoo.com”
}

}

$SERVER[“socket”] == “xx.xxx.xxx.xxx:443″ {

$HTTP[“host”] =~ “www.woohoo2.com” {
ssl.engine = “enable”
ssl.pemfile = var.confdir + “/www.woohoo2.com.ext.pem”
ssl.ca-file = var.confdir + “/gd_intermediate.crt”
server.name = var.confdir + “/www.woohoo2.com”
}

}

I guess it won’t work with virtual ips. Anyone know about this?

Reply

5 soraver February 23, 2009 at 12:49 pm

be carefull
sometimes server.bind does not work.

for me at least it didnt. i had to comment the ipv6 line
#include_shell “/usr/share/lighttpd/use-ipv6.pl”
that was above server.socket in my example config file in debian lenny.

Reply

6 Gokul July 19, 2010 at 7:31 am

you can simply use

$HTTP[“host”] =~ “yourdomain” {
server.bind = “yourip”
server.port = 80
}

Reply

7 Gokul July 19, 2010 at 9:14 am

The above command has a small issue,

The easy work around is goto your /etc/hosts file and set the IP against each domain

That will solve this issue.

Reply

Leave a Comment

Previous post:

Next post: