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 know that similar questions have been asked, but the available answers are not very clear, so please bear with me.

After setting up a few <VirtualHost>s in apache, I'd like to configure the _default_ ServerName so that it returns the 404 message. I.e., unless some explicitly available domain is specified in the Host http header, return 404. (Ideally something more direct than pointing to a now-nonexistent directory.)

Any help would be greatly appreciated.

share|improve this question
up vote 18 down vote accepted

Did you try:

Redirect 404 /
ErrorDocument 404 "Page Not Found"

in the default VirtualHost?

share|improve this answer
Thanks, that did it! Since it's clear my low level of expertise, I might add for my fellow newbies that the default server should appear first. (This took me a while to figure out!) – ezequiel-garzon Feb 5 '11 at 13:25
NOTE that if the ErrorDocument points to a file or url inside that vhost, it will also return a 404, thus generating an internal server error. – Cyril N. May 14 '15 at 11:53
This answer would work for sites where all the vhosts are contained in a single file (Eugene Fidelin's answer is more complete). When using separate .conf files for each site with a2ensite, I could not figure out how to load the default (404) configuration first. – Andrew Swift Sep 3 '15 at 9:08

Here is example of 000-default.conf that will return 404 error if server name is not configured for Apache

<VirtualHost *:80>
  ServerName default
  Redirect 404 /
<VirtualHost _default_:80>
  Redirect 404 /
share|improve this answer
I can confirm that the second part works when all the vhosts are configured in a single file (I put it first). – Andrew Swift Sep 3 '15 at 9:11

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.