The asterisks match all addresses, so the main server
serves no requests. Due to the fact that
www.domain.tld is first in the configuration
file, it has the highest priority and can be seen as the
default or primary server.

Setup 1: The server machine has one IP
address (111.22.33.44) which resolves to the
name server.domain.tld. There are two aliases
(CNAMEs) www.domain.tld and
www.sub.domain.tld for the address
111.22.33.44.

Apart from localhost there are no
unspecified addresses/ports, therefore the main server
only serves localhost requests. Due to the
fact that www.domain.tld has the highest
priority it can be seen as the default or
primary server.

Setup 2: The server machine has two IP
addresses (111.22.33.44 and
111.22.33.55) which resolve to the names
server1.domain.tld and
server2.domain.tld respectively. The alias
www.domain.tld should be used for the main
server which should also catch any unspecified addresses.
We want to use a virtual host for the alias
www.otherdomain.tld and another virtual host,
with server name www.sub.domain.tld, should
catch any request to hostnames of the form
*.sub.domain.tld. The address
111.22.33.55 should be used for the virtual
hosts.

Any request to an address other than
111.22.33.55 will be served from the main
server. A request to 111.22.33.55 with an
unknown or no Host: header will be served
from www.otherdomain.tld.

Setup 3: The server machine has two IP
addresses (192.168.1.1 and
111.22.33.55). The machine is sitting between
an internal (intranet) network and an external (internet)
network. Outside of the network, the name
server1.domain.tld resolves to the external
address (111.22.33.55), but inside the
network, that same name resolves to the internal address
(192.168.1.1).

The server can be made to respond to internal and
external requests with the same content, with just one
VirtualHost section.

Now requests from both networks will be served from the
same VirtualHost

Setup 4: You have multiple domains going
to the same IP and also want to serve multiple ports. By
defining the ports in the "NameVirtualHost" tag, you can
allow this to work. If you try using <VirtualHost
name:port> without the NameVirtualHost name:port or you
try to use the Port directive, your configuration will not
work.

Setup 1: The server machine has two IP
addresses (111.22.33.44 and
111.22.33.55) which resolve to the names
server.domain.tld and
www.otherdomain.tld respectively. The hostname
www.domain.tld is an alias (CNAME) for
server.domain.tld and will represent the main
server.

The main server can never catch a request, because all IP
addresses of our machine are in use for IP-based virtual
hosts (only localhost requests can hit the
main server).

Setup 3: The server machine has two IP
addresses (111.22.33.44 and
111.22.33.55) which resolve to the names
server.domain.tld and
www-cache.domain.tld respectively. The
hostname www.domain.tld is an alias (CNAME)
for server.domain.tld and will represent the
main server. www-cache.domain.tld will become
our proxy-cache listening on port 8080, while the web
server itself uses the default port 80.

The main server can never catch a request, because all IP
addresses (apart from localhost) of our
machine are in use for IP-based virtual hosts. The web
server can only be reached on the first address through
port 80 and the proxy only on the second address through
port 8080.

Setup: The server machine has three IP
addresses (111.22.33.44,
111.22.33.55 and 111.22.33.66)
which resolve to the names server.domain.tld,
www.otherdomain1.tld and
www.otherdomain2.tld respectively. The address
111.22.33.44 should be used for a couple of
name-based vhosts and the other addresses for IP-based
vhosts.

Setup: The server machine has one IP
address (111.22.33.44) which resolves to the
name www.domain.tld. If we don't have the
option to get another address or alias for our server we
can use port-based vhosts if we need a virtual host with a
different configuration.

Using such a default vhost with a wildcard port
effectively prevents any request going to the main
server.
A default vhost never serves a request that was sent to
an address/port that is used for name-based vhosts. If
the request contained an unknown or no Host:
header it is always served from the primary name-based
vhost (the vhost for that address/port appearing first in
the configuration file).
You can use AliasMatch
or RewriteRule
to rewrite any request to a single information page (or
script).

Setup 2: Same as setup 1, but the server
listens on several ports and we want to use a second
_default_ vhost for port 80.

The default vhost for port 80 (which must appear
before any default vhost with a wildcard port) catches
all requests that were sent to an unspecified IP address.
The main server is never used to serve a request.

Setup 3: We want to have a default vhost
for port 80, but no other default vhosts.

Setup: The name-based vhost with the
hostname www.otherdomain.tld (from our name-based example, setup 2) should get
its own IP address. To avoid problems with name servers or
proxies who cached the old IP address for the name-based
vhost we want to provide both variants during a migration
phase.
The solution is easy, because we can simply add the new IP
address (111.22.33.66) to the
VirtualHost directive.

Setup: We have a server with two
name-based vhosts. In order to match the correct virtual
host a client must send the correct Host:
header. Old HTTP/1.0 clients do not send such a header and
Apache has no clue what vhost the client tried to reach
(and serves the request from the primary vhost). To provide
as much backward compatibility as possible we create a
primary vhost which returns a single page containing links
with an URL prefix to the name-based virtual hosts.

Due to the ServerPath
directive a request to the URL
http://www.sub1.domain.tld/sub1/ is
always served from the sub1-vhost.
A request to the URL
http://www.sub1.domain.tld/ is only served
from the sub1-vhost if the client sent a correct
Host: header. If no Host:
header is sent the client gets the information page from
the primary host.
Please note that there is one oddity: A request to
http://www.sub2.domain.tld/sub1/ is also
served from the sub1-vhost if the client sent no
Host: header.
The RewriteRule directives are used to make
sure that a client which sent a correct
Host: header can use both URL variants,
i.e., with or without URL prefix.