How to close a connection if the requested host isn't a virtual host in apache

On my web server I have a bunch of websites defined using VirtualHosts. Currently if I request a website from my webserver that is not defined as a virtual host, I will get back the first virtual host in the list.

I would like to make it so that any requests that ask for a website not defined in a virtual host will just close the connection, both for HTTP and HTTPS. I imagine this will involve creating default and default-ssl virtual hosts but I am unsure what exactly to put in them.


Solution 1:

Use mod_security to make a 'drop' action rule for any request coming by. This closes the session by sending a FIN packet to the client.

Place your rule in the _default_ virtual host in Apache, which is described here and here.