4.4. Creating a Default Address-Based Virtual Host
Problem
You want to create a virtual host to catch all requests that don’t map to one of your address-based virtual hosts.
Solution
Use the _default_ keyword to designate a default host:
<VirtualHost _default_>
DocumentRoot /www/htdocs
</VirtualHost>Discussion
The _default_ keyword
creates a virtual host that catches all requests for any
address:port
combinations for which there is no virtual host configured.
The _default_ directive may—and should—be used in conjunction with a particular port number, such as:
<VirtualHost _default_:443>
Using this syntax means that the specified virtual host catches all requests to port 443, on all addresses for which there is not an explicit virtual host configured. SSL virtual hosts are usually set up using the _default_ syntax, so you’ll see this syntax used in the default SSL configuration file, along with the necessary directives to enable SSL.
_default_ typically does not
work as people expect in the case of name-based virtual hosts. It does
not match names for which there are no virtual host sections, only
address:port
combinations for which there are no virtual hosts configured. If you
wish to create a default name-based host, see Recipe 4.2.
See Also
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access