Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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>
        <Directory /var/www/dl.domain.com/public_html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

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

        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 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

My apache2.conf

http://www.speedyshare.com/files/29107024/apache2.conf

Thanks for the help

share|improve this question

2 Answers 2

Example config:

NameVirtualHost *:80

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

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

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

http://httpd.apache.org/docs/2.2/vhosts/name-based.html#using

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.

share|improve this answer
    
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 '11 at 3:04
    
@rafaame If you think it answered your question, then please mark the answer as "accepted". –  LazyOne Jun 23 '11 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

share|improve this answer

Your Answer

 
discard

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.