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