Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm not new to apache, but I'm pulling my hair out on this one.

I can't get a 2nd VirtualHost up on a particular IP. It seems to just use the default VirtualHost for that IP.

I have a server which owns two IP addresses. It runs on ports 80 and 443 on both IPs, such that I have four NameVirtualHosts e.g.


Now I have a default (i.e. file is named such that it would be sourced before the next one) VirtualHost for defined as

    CustomLog /var/log/apache2/ip2-80-access.log combined 
    ErrorLog /var/log/apache2/ip2-80-error.log

And a 2nd one

    DocumentRoot /var/www/
    CustomLog /var/log/apache2/ip2-80-access.log combined 
    ErrorLog /var/log/apache2/ip2-80-error.log

DNS is set up so that points to

But when I try to access I get a 404 not found. It seems apache is ignoring my 2nd name-based and ip-based virtualhost.

I'm using Apache 2.2 on Debian 6 (Squeeze). Please note: I am not trying to get apache to choose a virtual host for SSL here (I am aware of limitations/SNI etc.), this is standard port 80.

share|improve this question

Use apache2ctl -S to list the virtualhosts and defaults.

This shows that apache is selecting default VirtualHost for this IP:Port as the one for the specified host name:

VirtualHost configuration:     is a NameVirtualHost
         default server (/etc/apache2/sites-enabled/
         port 80 namevhost (/etc/apache2/sites-enabled/
         port 80 namevhost (/etc/apache2/sites-enabled/    is a NameVirtualHost
         ...     is a NameVirtualHost

i.e. I had thought that because I was supplying a host name that matched a VirtualHost's ServerName directive, and not supplying a ServerName in the default, that the 2nd one would be chosen.

However, what Apache seems to do is use the hostname for from /etc/hosts as the hostname for any requests on that IP. This is a bit opaque IMO.

So 2 alternative ways to get it working:

  1. change the hostname in /etc/hosts e.g. to Restart Apache and now requests for work. Of course, this is really proof of concept and you probably want your server name to match the main server name.

  2. add a ServerName directive to the first VirtualHost. It can be anything, e.g. goaway.local. This will mean that requests on the proper domain name get served by the correct VirtualHost block an that anything else (e.g. all those annoying direct IP vulnerability probes) are handled by the default, which can be set to deny everything.

share|improve this answer
+1 for the useful apachectl command (didn't know about that). However, I'm curious what is the point of that first/unused VirtualHost if you are not going to use it? Side note: I always setup my web/app servers as if it was a member in a cluster, so their hostnames will never match that of the site URL (so it would have been covered by alt 1). – Martin L. Jul 9 '13 at 21:05
Thanks. I was of the mindset at the time that it was cleaner/safer/easier to maintain the default as a No-no-go-away, and then to have the more general stuff in a nice clean separate virtual host. Actually I abandoned that and do now use the default one with a RewriteRule to check that the person acceseed it via the correct domain. – artfulrobot Jul 10 '13 at 15:14

Your Answer


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.