examples.html revision 27d310a14d63b16cccec3f3fffba5e1303233a53
fa9e4066f08beec538e775443c5be79dd423fcabahrens<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
441d80aa4f613b6298fc8bd3151f4be02dbf84fclling<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
fa9e4066f08beec538e775443c5be79dd423fcabahrens BGCOLOR="#FFFFFF"
fa9e4066f08beec538e775443c5be79dd423fcabahrens TEXT="#000000"
fa9e4066f08beec538e775443c5be79dd423fcabahrens LINK="#0000FF"
fa9e4066f08beec538e775443c5be79dd423fcabahrens VLINK="#000080"
fa9e4066f08beec538e775443c5be79dd423fcabahrens ALINK="#FF0000"
fa9e4066f08beec538e775443c5be79dd423fcabahrens<!--#include virtual="header.html" -->
fa9e4066f08beec538e775443c5be79dd423fcabahrens<H1 ALIGN="CENTER">Virtual Host examples for common setups</H1>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<LI><A HREF="#purename">Simple name-based vhosting</A>
55434c770c89aa1b84474f2559a106803511aba0ek<LI><A HREF="#name">More complicated name-based vhosts</A>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<LI><A HREF="#default">Using <CODE>_default_</CODE> vhosts</A>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<LI><A HREF="#migrate">Migrating a named-based vhost to an IP-based vhost</A>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<LI><A HREF="#serverpath">Using the <CODE>ServerPath</CODE> directive</A>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<H3><A NAME="purename">Simple name-based vhosting</A></H3>
fa9e4066f08beec538e775443c5be79dd423fcabahrens The server machine has a primary name <SAMP>server.domain.tld</SAMP>.
fa9e4066f08beec538e775443c5be79dd423fcabahrens There are two aliases (CNAMEs) <SAMP>www.domain.tld</SAMP> and
b1b8ab34de515a5e83206da22c3d7e563241b021lling <SAMP>www.sub.domain.tld</SAMP> for the address <SAMP>server.domain.tld</SAMP>.
fa9e4066f08beec538e775443c5be79dd423fcabahrens NameVirtualHost *
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost *>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost *>
a2eea2e101e6a163a537dcc6d4e3c4da2a0ea5b2ahrens </VirtualHost>
e7437265dc2a4920c197ed4337665539d358b22cahrens The asterisks match all addresses, so the main server serves no
f18faf3f3e5def85fdfff681617d227703ace2adek requests. Due to the fact that <SAMP>www.domain.tld</SAMP> is first
f18faf3f3e5def85fdfff681617d227703ace2adek in the configuration file, it has the highest priority and can be
fa9e4066f08beec538e775443c5be79dd423fcabahrens seen as the <CITE>default</CITE> or <CITE>primary</CITE> server.
fa9e4066f08beec538e775443c5be79dd423fcabahrens </BLOCKQUOTE>
fa9e4066f08beec538e775443c5be79dd423fcabahrens<H3><A NAME="name">More complicated name-based vhosts</A></H3>
fa9e4066f08beec538e775443c5be79dd423fcabahrens The server machine has one IP address (<SAMP>111.22.33.44</SAMP>)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks which resolves to the name <SAMP>server.domain.tld</SAMP>.
fa9e4066f08beec538e775443c5be79dd423fcabahrens There are two aliases (CNAMEs) <SAMP>www.domain.tld</SAMP> and
fa9e4066f08beec538e775443c5be79dd423fcabahrens <SAMP>www.sub.domain.tld</SAMP> for the address <SAMP>111.22.33.44</SAMP>.
fa9e4066f08beec538e775443c5be79dd423fcabahrens NameVirtualHost 111.22.33.44
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.44>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.44>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
fa9e4066f08beec538e775443c5be79dd423fcabahrens Apart from <SAMP>localhost</SAMP> there are no unspecified
fa9e4066f08beec538e775443c5be79dd423fcabahrens addresses/ports, therefore the main server only serves
fa9e4066f08beec538e775443c5be79dd423fcabahrens that <SAMP>www.domain.tld</SAMP> has the highest priority
fa9e4066f08beec538e775443c5be79dd423fcabahrens </BLOCKQUOTE>
fa9e4066f08beec538e775443c5be79dd423fcabahrens The server machine has two IP addresses (<SAMP>111.22.33.44</SAMP>
fa9e4066f08beec538e775443c5be79dd423fcabahrens which resolve to the names <SAMP>server1.domain.tld</SAMP> and
fa9e4066f08beec538e775443c5be79dd423fcabahrens The alias <SAMP>www.domain.tld</SAMP> should be used for the
fa9e4066f08beec538e775443c5be79dd423fcabahrens main server which should also catch any unspecified addresses.
fa9e4066f08beec538e775443c5be79dd423fcabahrens We want to use a virtual host for the alias
fa9e4066f08beec538e775443c5be79dd423fcabahrens <SAMP>www.otherdomain.tld</SAMP> and another virtual host,
fa9e4066f08beec538e775443c5be79dd423fcabahrens with server name <SAMP>www.sub.domain.tld</SAMP>, should
fa9e4066f08beec538e775443c5be79dd423fcabahrens catch any request to hostnames of the form
fa9e4066f08beec538e775443c5be79dd423fcabahrens used for the virtual hosts.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks NameVirtualHost 111.22.33.55
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.55>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.55>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
228975cc44c2290cc190960e5894ac6ce0863855ek Any request to an address other than <SAMP>111.22.33.55</SAMP>
228975cc44c2290cc190960e5894ac6ce0863855ek will be served from the main server. A request to
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <SAMP>111.22.33.55</SAMP> with an unknown or no <CODE>Host:</CODE>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw header will be served from <SAMP>www.otherdomain.tld</SAMP>.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw </BLOCKQUOTE>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw The server machine has two IP addresses (<SAMP>192.168.1.1</SAMP>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw and <SAMP>111.22.33.55</SAMP>). The machine is sitting between
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw an internal (intranet) network and an external (internet) network.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw Outside of the network, the name <SAMP>server1.domain.tld</SAMP>
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw resolves to the external address (<SAMP>111.22.33.55</SAMP>), but
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw inside the network, that same name resolves to the internal
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw The server can be made to respond to internal and external
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw requests with the same content, with just one <CODE>VirtualHost</CODE>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks NameVirtualHost 192.168.1.1
228975cc44c2290cc190960e5894ac6ce0863855ek NameVirtualHost 111.22.33.55
228975cc44c2290cc190960e5894ac6ce0863855ek <VirtualHost 192.168.1.1 111.22.33.55>
228975cc44c2290cc190960e5894ac6ce0863855ek ServerAlias server1
228975cc44c2290cc190960e5894ac6ce0863855ek </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Now requests from both networks will be served from the same
fa9e4066f08beec538e775443c5be79dd423fcabahrens You have multiple domains going to the same IP and also want
fa9e4066f08beec538e775443c5be79dd423fcabahrens to serve multiple ports. By defining the
fa9e4066f08beec538e775443c5be79dd423fcabahrens ports in the "NameVirtualHost" tag, you can allow this to
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks work. If you try using <VirtualHost name:port> without the
fa9e4066f08beec538e775443c5be79dd423fcabahrens NameVirtualHost name:port or you try to use the Port
fa9e4066f08beec538e775443c5be79dd423fcabahrens directive, your configuration will not work.
fa9e4066f08beec538e775443c5be79dd423fcabahrens NameVirtualHost 111.22.33.44:80
fa9e4066f08beec538e775443c5be79dd423fcabahrens NameVirtualHost 111.22.33.44:8080
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.44:80>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.44:8080>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.44:80>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.44:8080>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
fa9e4066f08beec538e775443c5be79dd423fcabahrens The server machine has two IP addresses (<SAMP>111.22.33.44</SAMP>
fa9e4066f08beec538e775443c5be79dd423fcabahrens which resolve to the names <SAMP>server.domain.tld</SAMP> and
fa9e4066f08beec538e775443c5be79dd423fcabahrens The hostname <SAMP>www.domain.tld</SAMP> is an alias (CNAME)
fa9e4066f08beec538e775443c5be79dd423fcabahrens for <SAMP>server.domain.tld</SAMP> and will represent the
fa9e4066f08beec538e775443c5be79dd423fcabahrens main server.
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.55>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
db870a07850e9c4ce547885b07cdf987749e7c7aahrens <SAMP>www.otherdomain.tld</SAMP> can only be reached through the
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks address <SAMP>111.22.33.55</SAMP>, while <SAMP>www.domain.tld</SAMP>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (which represents our main server).
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </BLOCKQUOTE>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Same as setup 1, but we don't want to have a dedicated main server.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.44>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.55>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The main server can never catch a request, because all IP addresses
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks of our machine are in use for IP-based virtual hosts
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (only <SAMP>localhost</SAMP> requests can hit the main server).
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </BLOCKQUOTE>
db870a07850e9c4ce547885b07cdf987749e7c7aahrens The server machine has two IP addresses (<SAMP>111.22.33.44</SAMP>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks which resolve to the names <SAMP>server.domain.tld</SAMP> and
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The hostname <SAMP>www.domain.tld</SAMP> is an alias (CNAME)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks for <SAMP>server.domain.tld</SAMP> and will represent the
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks main server.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <SAMP>www-cache.domain.tld</SAMP> will become our proxy-cache
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks listening on port 8080, while the web server itself uses the default
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Listen 111.22.33.44:80
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Listen 111.22.33.55:8080
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.44:80>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.55:8080>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <Directory proxy:>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Order Deny,Allow
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Deny from all
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Allow from 111.22.33
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </Directory>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The main server can never catch a request, because all IP addresses
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (apart from <SAMP>localhost</SAMP>) of our machine are in use for IP-based
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks virtual hosts. The web server can only be reached on the first address
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks through port 80 and the proxy only on the second address through port 8080.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </BLOCKQUOTE>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks<H3><A NAME="mixed">Mixed name-/IP-based vhosts</A></H3>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The server machine has three IP addresses (<SAMP>111.22.33.44</SAMP>,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <SAMP>111.22.33.55</SAMP> and <SAMP>111.22.33.66</SAMP>)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks which resolve to the names <SAMP>server.domain.tld</SAMP>,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <SAMP>www.otherdomain1.tld</SAMP> and <SAMP>www.otherdomain2.tld</SAMP>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks respectively.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The address <SAMP>111.22.33.44</SAMP> should we used for a couple
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks of name-based vhosts and the other addresses for IP-based vhosts.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks NameVirtualHost 111.22.33.44
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.44>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.44>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.44>
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.55>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.66>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The server machine has one IP address (<SAMP>111.22.33.44</SAMP>)
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks which resolves to the name <SAMP>www.domain.tld</SAMP>.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks If we don't have the option to get another address or alias
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks for our server we can use port-based vhosts if we need
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks a virtual host with a different configuration.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Listen 8080
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.44:8080>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks A request to <SAMP>www.domain.tld</SAMP> on port 80 is served
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks from the main server and a request to port 8080 is served from
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks the virtual host.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </BLOCKQUOTE>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks<H3><A NAME="default">Using <CODE>_default_</CODE> vhosts</A></H3>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Catching <EM>every</EM> request to any unspecified IP address and port,
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <EM>i.e.</EM>, an address/port combination that is not used for any other
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks virtual host.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost _default_:*>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Using such a default vhost with a wildcard port effectively
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks prevents any request going to the main server.<BR>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks A default vhost never serves a request that was sent to an
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks address/port that is used for name-based vhosts. If the request
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks contained an unknown or no <CODE>Host:</CODE> header it is
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks always served from the primary name-based vhost (the
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks vhost for that address/port appearing first in the configuration
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks You can use
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <A HREF="/mod/mod_alias.html#aliasmatch"><CODE>AliasMatch</CODE></A>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <A HREF="/mod/mod_rewrite.html#RewriteRule"><CODE>RewriteRule</CODE></A>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks to rewrite any request to a single information page (or script).
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </BLOCKQUOTE>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Same as setup 1, but the server listens on several ports and
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks we want to use a second <CODE>_default_</CODE> vhost for port 80.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost _default_:80>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost _default_:*>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The default vhost for port 80 (which <EM>must</EM> appear before
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks any default vhost with a wildcard port) catches all requests that
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks were sent to an unspecified IP address. The main server is
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks never used to serve a request.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </BLOCKQUOTE>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks We want to have a default vhost for port 80, but no other default vhosts.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost _default_:80>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks A request to an unspecified address on port 80 is served from the
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks default vhost any other request to an unspecified address and port
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks is served from the main server.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </BLOCKQUOTE>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks<H3><A NAME="migrate">Migrating a name-based vhost to an IP-based vhost</A></H3>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The name-based vhost with the hostname
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <SAMP>www.otherdomain.tld</SAMP> (from our <A HREF="#name">name-based</A>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks example, setup 2) should get its own IP address.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks To avoid problems with name servers or proxies who cached the old
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks IP address for the name-based vhost we want to provide both variants
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks during a migration phase.<BR>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The solution is easy, because we can simply add the new IP address
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks (<SAMP>111.22.33.66</SAMP>) to the <CODE>VirtualHost</CODE> directive.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks NameVirtualHost 111.22.33.55
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.55 111.22.33.66>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.55>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks The vhost can now be accessed through the new address (as an IP-based
fa9e4066f08beec538e775443c5be79dd423fcabahrens vhost) and through the old address (as a name-based vhost).
fa9e4066f08beec538e775443c5be79dd423fcabahrens </BLOCKQUOTE>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks<H3><A NAME="serverpath">Using the <CODE>ServerPath</CODE> directive</A></H3>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks We have a server with two name-based vhosts. In order to match the correct
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks virtual host a client must send the correct <CODE>Host:</CODE> header.
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Old HTTP/1.0 clients do not send such a header and Apache has no clue
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks what vhost the client tried to reach (and serves the request from
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks the primary vhost). To provide as much backward compatibility
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks as possible we create a primary vhost which returns a single page
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks containing links with an URL prefix to the name-based virtual hosts.
fa9e4066f08beec538e775443c5be79dd423fcabahrens NameVirtualHost 111.22.33.44
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.44>
fa9e4066f08beec538e775443c5be79dd423fcabahrens # primary vhost
fa9e4066f08beec538e775443c5be79dd423fcabahrens RewriteEngine On
fa9e4066f08beec538e775443c5be79dd423fcabahrens </VirtualHost>
fa9e4066f08beec538e775443c5be79dd423fcabahrens <VirtualHost 111.22.33.44>
fa9e4066f08beec538e775443c5be79dd423fcabahrens ServerPath /sub1/
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks RewriteEngine On
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks <VirtualHost 111.22.33.44>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks ServerPath /sub2/
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks RewriteEngine On
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks </VirtualHost>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks Due to the <A HREF="/mod/core.html#serverpath"><CODE>ServerPath</CODE></A>
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks directive a request to the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock URL <SAMP>http://www.sub1.domain.tld/sub1/</SAMP> is <EM>always</EM>
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock served from the sub1-vhost. <BR>
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock A request to the URL <SAMP>http://www.sub1.domain.tld/</SAMP>
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock is only served from the sub1-vhost if the client sent a correct
ecd6cf800b63704be73fb264c3f5b6e0dafc068dmarks If no <CODE>Host:</CODE> header is sent the client gets the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock information page from the primary host.<BR>
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock Please note that there is one oddity: A request to
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock <SAMP>http://www.sub2.domain.tld/sub1/</SAMP> is also served from
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock the sub1-vhost if the client sent no <CODE>Host:</CODE> header. <BR>
e45ce728996d8e573eecb27f555fb86aaff0cafdahrens The <CODE>RewriteRule</CODE> directives are used to make sure that
e45ce728996d8e573eecb27f555fb86aaff0cafdahrens a client which sent a correct <CODE>Host:</CODE> header can use
e45ce728996d8e573eecb27f555fb86aaff0cafdahrens both URL variants, <EM>i.e.</EM>, with or without URL prefix.
e45ce728996d8e573eecb27f555fb86aaff0cafdahrens </BLOCKQUOTE>
e45ce728996d8e573eecb27f555fb86aaff0cafdahrens<!--#include virtual="footer.html" -->