I have Apache2 configured in a debian box with virtual hosts. I have several domains pointing to the box's IP address. The domains whose virtual hosts are configured works perfectly. But if I type in the browser a domain that is pointing to the box but whose the virtual host is not configured, I get to a random virtual host of another domain in the box. Not a random, but one of the virtual hosts (always the same) but I dunno why it is it. The correct would be that the domains that are not configured as virtual hosts return a hostname error or something, right?

Does someone know how to fix the problem?

One of my virtual hosts config file:

<VirtualHost *:80>
        ServerAdmin mail@domain.com
        ServerName dl.domain.com

        DocumentRoot /var/www/dl.domain.com/public_html/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        <Directory /var/www/dl.domain.com/public_html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from ::1/128


My apache2.conf


Thanks for the help

2 Answers 2


Example config:

NameVirtualHost *:80

<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain

The first virtual host defined will act as a default host.


If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a container and list it first in the configuration file.

"The correct would be that the domains that are not configured as virtual hosts return a hostname error or something, right?"

If you really want this behaviour just create virtual host, place it before all other VirtualHost entries and point into empty folder. With no documents to serve it will give you 403 error.

  • Thanks. Now I understand why there is a virtual host called 000-default inside directory sites-enabled in the default apache2 installation.
    – rafaame
    Jun 23, 2011 at 3:04
  • @rafaame If you think it answered your question, then please mark the answer as "accepted".
    – LazyOne
    Jun 23, 2011 at 8:55

To help debug issues like this running 'apache2ctl -s' [1] will show how and what order apache is matching vhosts.

[1]: apache2ctl may be named apachectl on some distros

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.