From 6be5a9e6371cba71091be0a7cf24e9cf2030b588 Mon Sep 17 00:00:00 2001
From: Rich Bowen The virtual host code was completely rewritten in
- Apache 1.3. This document attempts to explain
- exactly what Apache does when deciding what virtual host to
- serve a hit from. With the help of the new
- This document attempts to explain
+ exactly what Apache HTTP Server does when deciding what virtual host to
+ serve a request from. If you just want to make it work without
understanding how, here are some
examples. There is a main_server which consists of all the
definitions appearing outside of
@@ -53,17 +49,15 @@
The directives
- The
+ The main_server has no default
- Port numbers specified in the If the client submitted a HTTP/1.0 request without
If no matching vhost could be found the request is served
- from the first vhost with a matching port number that is on the
- list for the IP to which the client connected (as already
- mentioned before). The virtual host code was completely rewritten in
- Apache 1.3. This document attempts to explain
- exactly what Apache does when deciding what virtual host to
- serve a hit from. With the help of the new
- This document attempts to explain
+ exactly what Apache HTTP Server does when deciding what virtual host to
+ serve a request from. If you just want to make it work without
understanding how, here are some
@@ -40,7 +36,7 @@
There is a main_server which consists of all the
definitions appearing outside of
@@ -49,17 +45,15 @@
The directives
- The
+ The main_server has no default
- NameVirtualHost
- directive virtual host configuration should be a lot easier and
- safer than with versions prior to 1.3. Config File Parsing
Config File Parsing
+Configuration File Parsing
<VirtualHost>
sections.ServerName
and
- ServerPath
- can appear anywhere within the definition of a server. However,
+ ServerName
directive
+ may appear anywhere within the definition of a server. However,
each appearance overrides the previous appearance (within that
server).ServerPath
, or ServerAlias
. The
- default ServerName
is deduced from the server's IP
- address.ServerAlias
. The default ServerName
,
+ if not specified, is deduced from the server's IP address.
VirtualHost
directive do
not influence what port numbers Apache will listen on, they only discriminate between
@@ -280,15 +274,10 @@
Host:
header field we don't know to what server
- the client tried to connect and any existing
- ServerPath
is matched against the URI from the
- request. The first matching path on the list is used and the
- request is served from that vhost.NameVirtualHost
directive.
- ServerAlias
and ServerPath
+ ServerAlias
checks are never performed for an IP-based vhost._default_
@@ -341,13 +330,6 @@
matching process. Apache always uses the real port to which
the client sent the request.ServerPath
directive exists which is a
- prefix of another ServerPath
directive that
- appears later in the configuration file, then the former will
- always be matched and the latter will never be matched. (That
- is assuming that no Host:
header field was
- available to disambiguate the two.)NameVirtualHost
and
VirtualHost
definitions in your configuration to
ensure better readability.ServerPaths
which are prefixes of
- other ServerPaths
. If you cannot avoid this then
- you have to ensure that the longer (more specific) prefix
- vhost appears earlier in the configuration file than the
- shorter (less specific) prefix (i.e., "ServerPath
- /abc" should appear after "ServerPath /abc/def").ServerPath
, or ServerAlias
. The
- default ServerName
is deduced from the server's IP
- address.ServerAlias
. The default ServerName
,
+ if not specified, is deduced from the server's IP address.
Port numbers specified in the VirtualHost
directive do
not influence what port numbers Apache will listen on, they only discriminate between
@@ -276,15 +270,10 @@
If the client submitted a HTTP/1.0 request without
Host:
header field we don't know to what server
- the client tried to connect and any existing
- ServerPath
is matched against the URI from the
- request. The first matching path on the list is used and the
- request is served from that vhost.
If no matching vhost could be found the request is served - from the first vhost with a matching port number that is on the - list for the IP to which the client connected (as already - mentioned before).
+ the client tried to connect to. In this case, the first virtual host + (that is, the one listed first in the server configuration file) for + the IP address and port to which the client connected, is + used to serve this request. @@ -322,7 +311,7 @@ corresponding address set which must be defined with aNameVirtualHost
directive.
- ServerAlias
and ServerPath
+ ServerAlias
checks are never performed for an IP-based vhost._default_
@@ -337,13 +326,6 @@
matching process. Apache always uses the real port to which
the client sent the request.ServerPath
directive exists which is a
- prefix of another ServerPath
directive that
- appears later in the configuration file, then the former will
- always be matched and the latter will never be matched. (That
- is assuming that no Host:
header field was
- available to disambiguate the two.)NameVirtualHost
and
VirtualHost
definitions in your configuration to
ensure better readability.ServerPaths
which are prefixes of
- other ServerPaths
. If you cannot avoid this then
- you have to ensure that the longer (more specific) prefix
- vhost appears earlier in the configuration file than the
- shorter (less specific) prefix (i.e., "ServerPath
- /abc" should appear after "ServerPath /abc/def").mod_vhost_alias
with Apache httpd. Alternatively,
- mod_rewrite
can
+ mod_rewrite can
be used.
Both of these modules are disabled by default; you must enable
one of them when configuring and building Apache httpd if you want to
@@ -134,7 +134,7 @@ NameVirtualHost 111.22.33.44
ServerName
is used instead.
The other thing to determine is the document root (configured
- with DocumentRoot
and available to CGIs via the
+ with DocumentRoot
and available to CGI scripts via the
DOCUMENT_ROOT
environment variable). In a normal
configuration, this is used by the core module when
mapping URIs to filenames, but when the server is configured to
@@ -173,7 +173,9 @@ VirtualScriptAlias /www/hosts/%0/cgi-bin
hosting solution by just turning UseCanonicalName
Off
into UseCanonicalName DNS
. The server
name that is inserted into the filename is then derived from
- the IP address of the virtual host.
%0
+ references the requested servername, as indicated in the
+ Host:
header.
See the mod_vhost_alias
documentation for more usage
examples.
This is an adjustment of the above system, tailored for an
- ISP's homepages server. Using a slightly more complicated
- configuration, we can select substrings of the server name to
+ ISP's web hosting server. Using %2
,
+ we can select substrings of the server name to
use in the filename so that, for example, the documents for
www.user.isp.com
are found in
/home/user/www
. It uses a single cgi-bin
diff --git a/docs/manual/vhosts/mass.xml b/docs/manual/vhosts/mass.xml
index 29d8cd4f16..d86071a127 100644
--- a/docs/manual/vhosts/mass.xml
+++ b/docs/manual/vhosts/mass.xml
@@ -102,7 +102,7 @@ NameVirtualHost 111.22.33.44
pathname of the file that is used to satisfy the request. This
can be most easily done by using
Both of these modules are disabled by default; you must enable
one of them when configuring and building Apache httpd if you want to
@@ -128,7 +128,7 @@ NameVirtualHost 111.22.33.44
ServerName
is used instead.
The other thing to determine is the document root (configured
- with DocumentRoot
and available to CGIs via the
+ with DocumentRoot
and available to CGI scripts via the
DOCUMENT_ROOT
environment variable). In a normal
configuration, this is used by the core module when
mapping URIs to filenames, but when the server is configured to
@@ -168,7 +168,9 @@ VirtualScriptAlias /www/hosts/%0/cgi-bin
hosting solution by just turning UseCanonicalName
Off
into UseCanonicalName DNS
. The server
name that is inserted into the filename is then derived from
- the IP address of the virtual host.
%0
+ references the requested servername, as indicated in the
+ Host:
header.
See the
This is an adjustment of the above system, tailored for an
- ISP's homepages server. Using a slightly more complicated
- configuration, we can select substrings of the server name to
+ ISP's web hosting server. Using %2
,
+ we can select substrings of the server name to
use in the filename so that, for example, the documents for
www.user.isp.com
are found in
/home/user/www
. It uses a single cgi-bin
--
2.50.1