Apache2 disable catch all virtual host

apache-2.2apache-2.4virtualhost

I have a server (Ubuntu 14.04) where I host several websites.

I have added the following Apache2 configuration files in /etc/sites-available; and I have enabled those sites (symlink to /etc/sites-enabled):

www.domain1.com.conf

<VirtualHost *:80>
    ServerName www.domain1.com
    ServerAlias domain1.com
    DocumentRoot /var/www/domain1.com/www/
</VirtualHost>

www.domain2.com.conf

<VirtualHost *:80>
    ServerName www.domain2.com
    ServerAlias domain2.com
    DocumentRoot /var/www/domain2.com/www/
</VirtualHost>

etc.

However, when I point my browser directly to the IP of the server, Apache2 seems to match the first virtual host file included (ie www.domain1.com.conf).

Is there any way to disable this, or alternatively how would a 000-default.conf file (which would be loaded first) look like to force apache to close the HTTP connection without returning any data?

Best Answer

You can use _default_ vhosts:

<VirtualHost _default_:*>
DocumentRoot /www/default
</VirtualHost>

More here: http://httpd.apache.org/docs/2.0/vhosts/examples.html#default

Related Topic