Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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"
}
share|improve this question
    
can someone help? –  redhatengineer6 Jan 1 '13 at 16:16
    
Can you provide the configuration you currently have? –  Shane Madden Jan 1 '13 at 20:36
    
i am just starting from the default configuration..the configuration file is pretty long...and its same as default configuration...i have tried and tried different things but didn't work so reverted back to default now –  redhatengineer6 Jan 1 '13 at 20:44

1 Answer 1

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" 
  )
}
share|improve this answer
    
well you can check the config i have here and did NOT work webhostingtalk.com/showpost.php?p=8493934&postcount=17 –  redhatengineer6 Jan 1 '13 at 21:22
    
tried yours and didn't work either...did you check my config file webhostingtalk.com/showpost.php?p=8493934&postcount=17 –  redhatengineer6 Jan 1 '13 at 21:32
    
@redhatengineer6 Can you expand on what you mean by "didn't work"? Does the service start successfully, or with any errors during the start process? What steps are you taking to test? What happens when you try to access the server with a web browser - connectivity errors, HTTP errors, not getting the expected content? –  Shane Madden Jan 1 '13 at 21:37
    
here is the errors from the error.log in /var/log/lighttpd/error.log file webhostingtalk.com/showpost.php?p=8494007&postcount=23 –  redhatengineer6 Jan 1 '13 at 22:40
    
how to go to next line and enter codes on serverfault? –  redhatengineer6 Jan 1 '13 at 22:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.