Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 am rebuilding an old server. Only one of the five old sites need to go live and all five of the old sites point to the same IP address.

Unfortunately any time a request is made for one of the old sites via their own unique domain names they are passed the pages from the one site that I'm trying to make live. I would just like the old sites to display a 404 instead of the one site that I'm actually trying to make live.

As an example:

  • Site 1 ( []
  • Site 2 ( []
  • Site 3 ( []

I want to move site 1 live again. So I turned on apache on the machine with the IP address of, with all of site 1's files in the /var/www directory. When I browse to or I correctly see site 1. When I browse to and I also receive site 1 which is the problem.

Is there a way I can 404 any request which comes in without

Here is my sites-available:

NameVirtualHost *:80

LogFormat "%h %l %u %t \"%r\" %>s %b" common

<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All

<Directory />
  Order Deny,Allow
  Deny from all
  Options None
  AllowOverride None
  Options None

<Directory /var/www>
  Order Allow,Deny
  Allow from all

<VirtualHost *:80>
        DocumentRoot /var/www
        ErrorLog /var/log/
        CustomLog /var/log/ common

<VirtualHost _default_:*>
        ServerName unknown
        DocumentRoot /var/www_404
share|improve this question
up vote 3 down vote accepted

A request with no matching ServerName or ServerAlias will be served by the first block to load; just move your 404'ing VirtualHost to the top (its bindings should match what it's playing default for, so set it to *:80 - the wildcarded vhost won't get any requests without that.)

share|improve this answer
Thanks that worked perfectly! – InvertedAcceleration Mar 18 '11 at 17:03

For the default VirtualHost, try the following (at the top, not the bottom as you have it):

<VirtualHost _default_:*>
    DocumentRoot /var/www_404

Otherwise, it's going to try to search for a server named "Unknown" if you have it at the bottom ;-)

Alternatively, you can just specify the DocumentRoot outside of your VirtualHost directives to define a default location, as specified in the Apache documentation here

EDIT: Minor correction about the placement

share|improve this answer
From the VirtualHost documentation: "A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts. If the request contained an unknown or no Host: header it is always served from the primary name-based vhost (the vhost for that address/port appearing first in the configuration file)." Server name of "Unknown" is OK, as long as it's the first name-based vhost to load it'll get unmatched requests. – Shane Madden Mar 18 '11 at 16:55
True. And the alternative I noted at the bottom will also work. I've revised the answer to clarify it. – Hyppy Mar 18 '11 at 17:02
The tricky part with the first option is that the _default_:* port specification will be completely ignored by Apache except for ports other than 80, since there are vhosts set up on that port. From that doc page, this port specification only catches "an address/port combination that is not used for any other virtual host." – Shane Madden Mar 18 '11 at 17:15

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.