In apache2 by design, any http request with an unknown Host will be directed to the first loaded VirtualHost. Is there a way to disable this feature? Said differently, I want to have a web server where the user may only get to explicitly named VirtualHost definitions. Any other hostname not explicitly mentioned in a ServerName or ServerAlias line should be silently ignored.
Is this possible?
Listen 80
NameVirtualHost *
<VirtualHost _default_:*>
# Anything matching this host should be silently ignored.
</VirtualHost>
<VirtualHost *>
DocumentRoot /www/example1
ServerName www.example.com
</VirtualHost>
<VirtualHost *>
DocumentRoot /www/example2
ServerName www.example.org
</VirtualHost>
Update: As suggested below and elsewhere, silently ignoring a request might not be a good idea and perhaps breaks the RFC's for HTTP. However, since virtual hosts are designed to simulate have multiple separate physical HTTP servers, the silent ignore approach does not seem unreasonable to me. It would be the same as IP-based virtual hosting and firewalling off some of the IPs (perhaps not for all clients).