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

Posted on in Categories Howto, lighttpd, Linux last updated July 11, 2006
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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

7 comment

  1. 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

  2. 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?

  3. 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.

Leave a Comment