How to get apache to send a 404 based on no matching VirtualHost section (based on ServerName) being found?
A request with no matching ServerName
or ServerAlias
will be served by the first block to load; just move your 404'ing VirtualHost to the top (its bindings should match what it's playing default for, so set it to *:80
- the wildcarded vhost won't get any requests without that.)
For the default VirtualHost, try the following (at the top, not the bottom as you have it):
<VirtualHost _default_:*>
DocumentRoot /var/www_404
</VirtualHost>
Otherwise, it's going to try to search for a server named "Unknown" if you have it at the bottom ;-)
Alternatively, you can just specify the DocumentRoot outside of your VirtualHost directives to define a default location, as specified in the Apache documentation here
EDIT: Minor correction about the placement