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've got a few sites configured as VirtualHosts using Apache that have been working fine for a while. I recently changed the hostname of the server to one of the domain names that was being served, and also added it to /etc/hosts pointing to the server's external IP address.

Since I did that, accessing the domain from my laptop takes me to Apache's default "It works!" page. If I remove 000-default from /etc/apache2/sites-enabled/, it displays the correct site. Trying to access the site with the 'www.' prefix takes me to the correct site whether or not 000-default is in sites-enabled.

Based on all of that, I'm guessing the default config is serving up the default page because of how I've configured the hostname or /etc/hosts (or both), but I can't figure out how to disable that while leaving those settings as they are. Any suggestions welcome!

Edit - My current VirtualHost config looks like this:

<VirtualHost *:80>

    DocumentRoot /srv/www/domain

    ErrorLog /srv/www/domain/logs/error.log
    CustomLog /srv/www/domain/logs/access.log combined

To summarize: I have several VirtualHosts set up, and this is the only one not working properly. I can access just fine, but takes me to Apache's default "It works!" page. If I disable the 000-default config it shows the proper page. This only started happening after I set the hostname of the server to and added a line to /etc/hosts pointing to the server's external IP address. I'd like to leave those that way if possible.

Edit: I ran apache2ctl -S since /usr/sbin/apache2 -S gave me "apache2: bad user name ${APACHE_RUN_USER}". Here's the output:

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost (/etc/apache2/sites-enabled/other:1)
         port 80 namevhost (/etc/apache2/sites-enabled/another:1)
         port 80 namevhost (/etc/apache2/sites-enabled/domain:1)
Syntax OK
share|improve this question
is being used on the main httpd.conf file as ServerName ? or apache2ctl.conf you seem to be using ubuntu so it might differ the name. – Prix Oct 19 '10 at 17:34
up vote 6 down vote accepted

Lost this question the other day.

When you have a <VirtualHost> container without a ServerName component, it will use the default hostname. As 000-default probably doesn't have a ServerName component, and is the first alphabetically to be included, that is why it answers for and doesn't allow your explicitly declared hostname to work.

share|improve this answer
I see, any way to fix that? I want the default config to handle any unhandled domains, but I don't want it to handle that particular domain. – John Debs Oct 19 '10 at 18:24
give it a domain other than one that is used in a config, or rename it to zzz-default so that it is called last. – karmawhore Oct 19 '10 at 18:59
Okay, I think I understand it all now. I tried zzz-default but it's not the exact behavior I wanted. Setting ServerName in the default config works great, though. Thanks! – John Debs Oct 19 '10 at 20:15
thanks! Saved me time. – TsimoX Mar 16 at 14:55

Do you have a NameVirtualHost *:80 directive somewhere?


/usr/sbin/apache2 -S

That will tell you how apache is parsing the config file. Do you have configs that have actual IPs or all have the *? Do you have any missing the :80? Apache doesn't like mixing those.

Do you have a ServerName or ServerAlias in default?

share|improve this answer
Yup, I've got it in my /etc/apache2/posts.conf. I'll add a summary to the question that hopefully makes it more clear. – John Debs Oct 15 '10 at 5:05
Thanks, updated question with output. – John Debs Oct 15 '10 at 5:17
My 000-default config is untouched, it has no ServerName or ServerAlias directives. – John Debs Oct 15 '10 at 5:24
NameVirtualHost is deprecated. – Sam Jan 16 '15 at 6:31

Check ServerName and ServerAlias in VirtualHost directive:

<VirtualHost *:80>
ServerName domain
ServerAlias *


share|improve this answer
That's basically how things are set up now. I posted my config in the question. – John Debs Oct 15 '10 at 4:59

This worked:

<VirtualHost *:80>
    DocumentRoot /var/www/

when I had a typo, it did NOT work (the ServerName directive twice):

<VirtualHost *:80>
    DocumentRoot /var/www/

When I had the ServerName directive twice, it kept resolving to the first site listed (not shown here).

hope this helps somebody...

share|improve this answer

I had a similar problem, and fixed it by explicitly setting a ServerName in the main httpd.conf file, rather than letting apache automatically figure out it was. I assume that what apache decided was the same as my vhost (defined later), so the default one "won", overriding the vhost setting.

I just set the httpd.conf ServerName to a hostname that machine has, I'll never serve webpages for.

share|improve this answer

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.