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'm having a little trouble configuring name based Virtual Hosts.

I can start the server with "service apache2 start" with a blank httpd.conf file, and it will run with everything pointing to /var/www, as expected.


When I fill httpd.conf with:

# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/kevins_playground
ServerName home.coolkev.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/flatline_and_co
ServerName www.flatline_and_co.com

# Other directives here

</VirtualHost>

I get this error when running "service apache2 start"

root@kevin-server:/etc/apache2# service apache2 start
 * Starting web server apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Thu Jul 26 20:10:01 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

I found a solution,

  1. I removed all my changes to httpd.conf, for me, this left a blank file.
  2. I copied the existing default site file in ./sites-available/ for my two Virtual Hosts.
  3. I edited those two files and replaced values where it made sense, I think it should be obvious where they need changing (Website base folder, Website URL).
  4. I created sym-links like you are supposed to in ./sites-enabled/
  5. I restarted the web-server 'sudo service apache2 restart' and it worked.

I think the problem stemmed from the fact that while parsing the files, Apache discovered two files with "<VirtualHost>"s, my httpd.conf and the default website configuration in ./sites-available/

share|improve this question

migrated from stackoverflow.com Jul 27 '12 at 10:29

This question came from our site for professional and enthusiast programmers.

    
Does netstat -anp | grep 80 show any other processes currently bound to 0.0.0.0:80? –  sarnold Jul 27 '12 at 0:48
    
Just this: unix 3 [ ] STREAM CONNECTED 9050 1080/console-kit-da –  Kevin Johnson Jul 27 '12 at 0:52
    
Okay, good; that's unrelated. (It's a Unix domain socket, not a a TCP socket.) –  sarnold Jul 27 '12 at 1:01
    
Perhaps the problem is in those other directives. –  n.m. Jul 27 '12 at 1:05
    
oh no, sorry to confuse you, that is an actual comment, the configuration was taken directly from apache.org. Just modified for my situation –  Kevin Johnson Jul 27 '12 at 1:09
show 2 more comments

1 Answer 1

up vote 1 down vote accepted

As long as you did not touch the default vhost (which already contains a NameVirtualHost *:80 directive), you should not duplicate the default behaviour.

Since you have to suffer Debuntu, why not go with it and put your vhosts in /etc/apache2/sites-enabled/, one per file ?

share|improve this answer
    
Thats what I did, in the end. See the edit to my question. –  Kevin Johnson Jul 27 '12 at 19:02
add comment

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.