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/

7
  • Does netstat -anp | grep 80 show any other processes currently bound to 0.0.0.0:80?
    – sarnold
    Jul 27, 2012 at 0:48
  • Just this: unix 3 [ ] STREAM CONNECTED 9050 1080/console-kit-da
    – Kevin Johnson
    Jul 27, 2012 at 0:52
  • Okay, good; that's unrelated. (It's a Unix domain socket, not a a TCP socket.)
    – sarnold
    Jul 27, 2012 at 1:01
  • Perhaps the problem is in those other directives.
    – n.m.
    Jul 27, 2012 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, 2012 at 1:09

1 Answer 1

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 ?

1
  • Thats what I did, in the end. See the edit to my question. Jul 27, 2012 at 19:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .