Lighttpd virtual hosting configuration

centos6lighttpdvirtualhostvirtualization

I need help setting up virtual hosting in lighttpd.
i have the lighttpd default webpage in /var/www/lighttpd dir and i have created other dirs for my other websites /var/www/web1.com/public_html and /var/www/web2.com/public_html

I have tried to follow the documentation page on lighttpd websites and other guides online but haven't been successful. I just want to know what file do i edit and what do i add to be able to serve websites from the other virtual hosts/dirs?

full configuration is too long but here is what i added to default lighttpd.conf

$HTTP["host"] =~ "^www\.(.*)$" {
  url.redirect-code = 301
  url.redirect = (
    "/(.*)" => "http://%1/$1"
  )
}


$HTTP["host"] == "www.web1.com" {
#url.redirect  = (
#    "^/(.*)" => "http://web1.com/$1",
#  )
    server.document-root = "/var/www/web1.com/public_html"
#    accesslog.filename = "/var/www/web1.com/logs/error.log"
}

$HTTP["host"] == "web2.com" {
    server.document-root = "/var/www/web2.com/public_html"
#    accesslog.filename = "/var/www/web2.com/logs/error.log"
}

$HTTP["host"] == "web3.com" {
    server.document-root = "/var/www/web3.com/public_html"
#    accesslog.filename = "/var/www/web3.com/logs/error.log"
}

Best Answer

You'll want some configuration along these lines:

$HTTP["host"] == "web1.com" {
    server.document-root = "/var/www/web1.com/public_html"
}
$HTTP["host"] == "web2.com" {
    server.document-root = "/var/www/web2.com/public_html"
}

That should be all that's needed to get those two directories mapped to those two host headers. If that doesn't work, can you go into more detail about what kind of problems you're seeing when attempting to use this config?

Edit:

To have the www domains redirect to non-www, use a configuration like this:

$HTTP["host"] =~ "^www\.(.*)$" {
  url.redirect-code = 301
  url.redirect = (
    "/(.*)" => "http://%1/$1" 
  )
}
Related Topic