From: Eric Covener
The directives
- Listen,
- ServerName,
- ServerPath,
- and ServerAlias
+ ServerName and
+ ServerPath
can appear anywhere within the definition of a server. However,
each appearance overrides the previous appearance (within that
server).
The default value of the Listen field for
- main_server is 80. The main_server has no default
+
The main_server has no default
ServerPath, or ServerAlias. The
default ServerName is deduced from the server's IP
address.
The main_server Listen directive has two functions. One - function is to determine the default network port Apache will - bind to. The second function is to specify the port number - which is used in absolute URIs during redirects.
- -Unlike the main_server, vhost ports do not affect - what ports Apache listens for connections on.
- +Port numbers specified in the VirtualHost directive do
+ not influence what port numbers Apache will listen on, they only discriminate between
+ which VirtualHost will be selected to handle a request.
Each address appearing in the VirtualHost
directive can have an optional port. If the port is unspecified
- it defaults to the value of the main_server's most recent
- Listen statement. The special port *
+ it is treated as a wildcard port. The special port *
indicates a wildcard that matches any port. Collectively the
entire set of addresses (including multiple A
record results from DNS lookups) are called the vhost's
address set.
Unless a NameVirtualHost
- directive is used for a specific IP address the first vhost
- with that address is treated as an IP-based vhost. The IP
- address can also be the wildcard *.
If name-based vhosts should be used a
+ directive is used for the exact IP address and port pair in the
+ VirtualHost directive, Apache selects the best match
+ only on the basis of the IP address (or wildcard) and port number.
+ If there are multiple identical best matches, the first VirtualHost
+ appearing in the configuration file will be selected.
If you want Apache to further discriminate on the basis of the
+ HTTP Host header supplied by the client, the
NameVirtualHost directive must appear
- with the IP address set to be used for the name-based vhosts.
- In other words, you must specify the IP address that holds the
- hostname aliases (CNAMEs) for your name-based vhosts via a
- NameVirtualHost directive in your configuration
- file.
VirtualHost directives.
+
+ The name-based virtual host selection occurs only after the a single IP-based + virtual host has been selected, and only considers the set of virtual hosts + the carry an identical IP address and port pair.
+ +Hostnames can be used in place of IP addresses in a virtual host definition, + but it is resolved at startup and is not recommended.
+Multiple NameVirtualHost directives can be used
each with a set of VirtualHost directives but only
@@ -158,18 +158,6 @@
(To aid the readability of your configuration you should prefer the left variant.)
-After parsing the VirtualHost directive, the
- vhost server is given a default Listen equal to the
- port assigned to the first name in its VirtualHost
- directive.
The complete list of names in the VirtualHost
- directive are treated just like a ServerAlias (but
- are not overridden by any ServerAlias statement)
- if all names resolve to the same address set. Note that
- subsequent Listen statements for this vhost will not
- affect the ports assigned in the address set.
During initialization a list for each IP address is
generated and inserted into an hash table. If the IP address is
used in a NameVirtualHost directive the list
@@ -347,8 +335,7 @@
configuration file has the highest priority for its
corresponding address set.
-
Host: header field is never used during the
+ Host: header field is never used during the
matching process. Apache always uses the real port to which
the client sent the request.Listen by default. A wildcard port can be
specified (i.e., _default_:*) to catch
requests to any available port. This also applies to
- NameVirtualHost * vhosts.
+ NameVirtualHost * vhosts. Note that this is simply an
+ extension of the "best match" principle, as a specific and exact match
+ is favored over a wildcard.
The directives
-
The default value of the Listen field for
- main_server is 80. The main_server has no default
+
The main_server has no default
ServerPath, or ServerAlias. The
default ServerName is deduced from the server's IP
address.
The main_server Listen directive has two functions. One - function is to determine the default network port Apache will - bind to. The second function is to specify the port number - which is used in absolute URIs during redirects.
- -Unlike the main_server, vhost ports do not affect - what ports Apache listens for connections on.
- +Port numbers specified in the VirtualHost directive do
+ not influence what port numbers Apache will listen on, they only discriminate between
+ which VirtualHost will be selected to handle a request.
Each address appearing in the VirtualHost
directive can have an optional port. If the port is unspecified
- it defaults to the value of the main_server's most recent
- Listen statement. The special port *
+ it is treated as a wildcard port. The special port *
indicates a wildcard that matches any port. Collectively the
entire set of addresses (including multiple A
record results from DNS lookups) are called the vhost's
address set.
Unless a *.
If name-based vhosts should be used a
+ directive is used for the exact IP address and port pair in the
+ VirtualHost directive, Apache selects the best match
+ only on the basis of the IP address (or wildcard) and port number.
+ If there are multiple identical best matches, the first VirtualHost
+ appearing in the configuration file will be selected.
If you want Apache to further discriminate on the basis of the
+ HTTP Host header supplied by the client, the
NameVirtualHost directive must appear
- with the IP address set to be used for the name-based vhosts.
- In other words, you must specify the IP address that holds the
- hostname aliases (CNAMEs) for your name-based vhosts via a
- NameVirtualHost directive in your configuration
- file.
VirtualHost directives.
+
+ The name-based virtual host selection occurs only after the a single IP-based + virtual host has been selected, and only considers the set of virtual hosts + the carry an identical IP address and port pair.
+ +Hostnames can be used in place of IP addresses in a virtual host definition, + but it is resolved at startup and is not recommended.
+Multiple NameVirtualHost directives can be used
each with a set of VirtualHost directives but only
@@ -154,18 +154,6 @@
(To aid the readability of your configuration you should prefer the left variant.)
-After parsing the VirtualHost directive, the
- vhost server is given a default Listen equal to the
- port assigned to the first name in its VirtualHost
- directive.
The complete list of names in the VirtualHost
- directive are treated just like a ServerAlias (but
- are not overridden by any ServerAlias statement)
- if all names resolve to the same address set. Note that
- subsequent Listen statements for this vhost will not
- affect the ports assigned in the address set.
During initialization a list for each IP address is
generated and inserted into an hash table. If the IP address is
used in a NameVirtualHost directive the list
@@ -343,8 +331,7 @@
configuration file has the highest priority for its
corresponding address set.
Host: header field is never used during the
+ Host: header field is never used during the
matching process. Apache always uses the real port to which
the client sent the request.Listen by default. A wildcard port can be
specified (i.e., _default_:*) to catch
requests to any available port. This also applies to
- NameVirtualHost * vhosts.
+ NameVirtualHost * vhosts. Note that this is simply an
+ extension of the "best match" principle, as a specific and exact match
+ is favored over a wildcard.