≡ Menu

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

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: domain nixcraft.com
IP # 2: domain theos.in

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

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

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 for theos.in domain:
$SERVER["socket"] == "" {
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

Share this on:
{ 7 comments… add one }
  • slav0nic December 1, 2007, 6:34 pm

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

  • nixCraft December 1, 2007, 8:16 pm

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

  • Kathleen J Caunter January 12, 2008, 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

  • Nazz April 30, 2008, 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”] == “” {

    $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?

  • soraver February 23, 2009, 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.

  • Gokul July 19, 2010, 7:31 am

    you can simply use

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

    • Gokul July 19, 2010, 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.

Security: Are you a robot or human?

Leave a Comment