4

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/

  • Does `netstat -anp | grep 80` show any other processes currently bound to `0.0.0.0:80`? – sarnold Jul 27 '12 at 00:48
  • Just this: unix 3 [ ] STREAM CONNECTED 9050 1080/console-kit-da –  Jul 27 '12 at 00:52
  • Okay, good; that's unrelated. (It's a Unix domain socket, not a a TCP socket.) – sarnold Jul 27 '12 at 01:01
  • Perhaps the problem is in those other directives. –  Jul 27 '12 at 01:05
  • oh no, sorry to confuse you, that is an actual comment, the configuration was taken directly from [apache.org](http://httpd.apache.org/docs/2.2/vhosts/examples.html). Just modified for my situation –  Jul 27 '12 at 01:09
  • It seems to me that the problematic line is (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80 –  Jul 27 '12 at 02:51
  • I found [this ubuntuforums link](http://ubuntuforums.org/showthread.php?t=1480907) where someone had the same problem and it was caused by a duplicate NameVirtualHost statement in another config file. You're only supposed to have one of those per IPaddress+port combination. – Alan Curry Jul 27 '12 at 04:34

1 Answers1

1

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 ?

adaptr
  • 16,576
  • 23
  • 34