home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 May / Gamestar_62_2004-05_dvd.iso / Programy / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F252999_examples.html.en < prev    next >
Extensible Markup Language  |  2003-10-13  |  25KB  |  630 lines

  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
  4.         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  5.               This file is generated from xml source: DO NOT EDIT
  6.         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  7.       -->
  8. <title>VirtualHost Examples - Apache HTTP Server</title>
  9. <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
  10. <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
  11. <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
  12. <link href="../images/favicon.ico" rel="shortcut icon" /></head>
  13. <body id="manual-page"><div id="page-header">
  14. <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
  15. <p class="apache">Apache HTTP Server Version 2.0</p>
  16. <img alt="" src="../images/feather.gif" /></div>
  17. <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
  18. <div id="path">
  19. <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs-project/">Documentation</a> > <a href="../">Version 2.0</a> > <a href="./">Virtual Hosts</a></div><div id="page-content"><div id="preamble"><h1>VirtualHost Examples</h1>
  20. <div class="toplang">
  21. <p><span>Available Languages: </span><a href="../en/vhosts/examples.html" title="English"> en </a> |
  22. <a href="../ko/vhosts/examples.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
  23. </div>
  24.  
  25.  
  26.     <p>This document attempts to answer the commonly-asked questions about
  27.     setting up virtual hosts. These scenarios are those involving multiple
  28.     web sites running on a single server, via <a href="name-based.html">name-based</a> or <a href="ip-based.html">IP-based</a> virtual hosts. A document should be
  29.     coming soon about running sites on several servers behind a single
  30.     proxy server.</p>
  31.  
  32. </div>
  33. <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#purename">Running several name-based web
  34.     sites on a single IP address.</a></li>
  35. <li><img alt="" src="../images/down.gif" /> <a href="#twoips">Name-based hosts on more than one
  36.     IP address.</a></li>
  37. <li><img alt="" src="../images/down.gif" /> <a href="#intraextra">Serving the same content on
  38.     different IP addresses (such as an internal and external
  39.     address).</a></li>
  40. <li><img alt="" src="../images/down.gif" /> <a href="#port">Running different sites on different
  41.     ports.</a></li>
  42. <li><img alt="" src="../images/down.gif" /> <a href="#ip">IP-based virtual hosting</a></li>
  43. <li><img alt="" src="../images/down.gif" /> <a href="#ipport">Mixed port-based and ip-based virtual
  44.     hosts</a></li>
  45. <li><img alt="" src="../images/down.gif" /> <a href="#mixed">Mixed name-based and IP-based
  46.     vhosts</a></li>
  47. <li><img alt="" src="../images/down.gif" /> <a href="#default">Using <code>_default_</code>
  48.     vhosts</a></li>
  49. <li><img alt="" src="../images/down.gif" /> <a href="#migrate">Migrating a name-based vhost to an
  50.     IP-based vhost</a></li>
  51. <li><img alt="" src="../images/down.gif" /> <a href="#serverpath">Using the <code>ServerPath</code>
  52.     directive</a></li>
  53. </ul></div>
  54. <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  55. <div class="section">
  56. <h2><a name="purename" id="purename">Running several name-based web
  57.     sites on a single IP address.</a></h2>
  58.  
  59.     <p>Your server has a single IP address, and multiple aliases (CNAMES)
  60.     point to this machine in DNS. You want to run a web server for
  61.     <code>www.example1.com</code> and <code>www.example2.org</code> on this
  62.     machine.</p>
  63.  
  64.     <div class="note"><h3>Note</h3><p>Creating virtual
  65.           host configurations on your Apache server does not magically
  66.           cause DNS entries to be created for those host names. You
  67.           <em>must</em> have the names in DNS, resolving to your IP
  68.           address, or nobody else will be able to see your web site. You
  69.           can put entries in your <code>hosts</code> file for local
  70.           testing, but that will work only from the machine with those
  71.           hosts entries.</p>
  72.     </div>
  73.  
  74.     <div class="example"><h3>Server configuration</h3><p><code>
  75.     
  76.  
  77.     # Ensure that Apache listens on port 80<br />
  78.     Listen 80<br />
  79.     <br />
  80.     # Listen for virtual host requests on all IP addresses<br />
  81.     NameVirtualHost *<br />
  82.     <br />
  83.     <VirtualHost *><br />
  84.     <span class="indent">
  85.       DocumentRoot /www/example1<br />
  86.       ServerName www.example1.com<br />
  87.       <br />
  88.       # Other directives here<br />
  89.       <br />
  90.     </span>
  91.     </VirtualHost><br />
  92.     <br />
  93.     <VirtualHost *><br />
  94.     <span class="indent">
  95.       DocumentRoot /www/example2<br />
  96.       ServerName www.example2.org<br />
  97.       <br />
  98.       # Other directives here<br />
  99.       <br />
  100.     </span>
  101.     </VirtualHost>
  102.     </code></p></div>
  103.  
  104.     <p>The asterisks match all addresses, so the main server serves no
  105.     requests. Due to the fact that <code>www.example1.com</code> is first
  106.     in the configuration file, it has the highest priority and can be seen
  107.     as the <cite>default</cite> or <cite>primary</cite> server. That means
  108.     that if a request is received that does not match one of the specified
  109.     <code>ServerName</code> directives, it will be served by this first
  110.     <code>VirtualHost</code>.</p>
  111.  
  112.     <div class="note">
  113.             <h3>Note</h3>
  114.  
  115.             <p>You can, if you wish, replace <code>*</code> with the actual
  116.             IP address of the system. In that case, the argument to
  117.             <code>VirtualHost</code> <em>must</em> match the argument to
  118.             <code>NameVirtualHost</code>:</p>
  119.  
  120.             <div class="example"><p><code>
  121.             NameVirtualHost 172.20.30.40<br />
  122.                         <br />
  123.             <VirtualHost 172.20.30.40><br />
  124.                  # etc ...
  125.             </code></p></div>
  126.  
  127.            <p>However, it is additionally useful to use <code>*</code>
  128.            on systems where the IP address is not predictable - for
  129.            example if you have a dynamic IP address with your ISP, and
  130.            you are using some variety of dynamic DNS solution. Since
  131.            <code>*</code> matches any IP address, this configuration
  132.            would work without changes whenever your IP address
  133.            changes.</p>
  134.     </div>
  135.  
  136.     <p>The above configuration is what you will want to use in almost
  137.     all name-based virtual hosting situations. The only thing that this
  138.     configuration will not work for, in fact, is when you are serving
  139.     different content based on differing IP addresses or ports.</p>
  140.  
  141.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  142. <div class="section">
  143. <h2><a name="twoips" id="twoips">Name-based hosts on more than one
  144.     IP address.</a></h2>
  145.  
  146.       <div class="note">
  147.           <h3>Note</h3><p>Any of the
  148.           techniques discussed here can be extended to any number of IP
  149.           addresses.</p>
  150.     </div>
  151.  
  152.     <p>The server has two IP addresses. On one (<code>172.20.30.40</code>), we
  153.     will serve the "main" server, <code>server.domain.com</code> and on the
  154.     other (<code>172.20.30.50</code>), we will serve two or more virtual hosts.</p>
  155.  
  156.     <div class="example"><h3>Server configuration</h3><p><code>
  157.     
  158.  
  159.     Listen 80<br />
  160.         <br />
  161.     # This is the "main" server running on 172.20.30.40<br />
  162.     ServerName server.domain.com<br />
  163.     DocumentRoot /www/mainserver<br />
  164.         <br />
  165.     # This is the other address<br />
  166.     NameVirtualHost 172.20.30.50<br />
  167.         <br />
  168.     <VirtualHost 172.20.30.50><br />
  169.     <span class="indent">
  170.         DocumentRoot /www/example1<br />
  171.         ServerName www.example1.com<br />
  172.                <br />
  173.         # Other directives here ...<br />
  174.                 <br />
  175.     </span>
  176.     </VirtualHost><br />
  177.         <br />
  178.     <VirtualHost 172.20.30.50><br />
  179.     <span class="indent">
  180.         DocumentRoot /www/example2<br />
  181.         ServerName www.example2.org<br />
  182.                 <br />
  183.         # Other directives here ...<br />
  184.                 <br />
  185.     </span>
  186.     </VirtualHost>
  187.     </code></p></div>
  188.  
  189.     <p>Any request to an address other than <code>172.20.30.50</code> will be
  190.     served from the main server. A request to <code>172.20.30.50</code> with an
  191.     unknown hostname, or no <code>Host:</code> header, will be served from
  192.     <code>www.example1.com</code>.</p>
  193.  
  194.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  195. <div class="section">
  196. <h2><a name="intraextra" id="intraextra">Serving the same content on
  197.     different IP addresses (such as an internal and external
  198.     address).</a></h2>
  199.  
  200.     <p>The server machine has two IP addresses (<code>192.168.1.1</code>
  201.     and <code>172.20.30.40</code>). The machine is sitting between an
  202.     internal (intranet) network and an external (internet) network. Outside
  203.     of the network, the name <code>server.example.com</code> resolves to
  204.     the external address (<code>172.20.30.40</code>), but inside the
  205.     network, that same name resolves to the internal address
  206.     (<code>192.168.1.1</code>).</p>
  207.  
  208.     <p>The server can be made to respond to internal and external requests
  209.     with the same content, with just one <code>VirtualHost</code>
  210.     section.</p>
  211.  
  212.     <div class="example"><h3>Server configuration</h3><p><code>
  213.     
  214.  
  215.     NameVirtualHost 192.168.1.1<br />
  216.     NameVirtualHost 172.20.30.40<br />
  217.         <br />
  218.     <VirtualHost 192.168.1.1 172.20.30.40><br />
  219.     <span class="indent">
  220.         DocumentRoot /www/server1<br />
  221.         ServerName server.example.com<br />
  222.         ServerAlias server<br />
  223.     </span>
  224.     </VirtualHost>
  225.     </code></p></div>
  226.  
  227.     <p>Now requests from both networks will be served from the same
  228.     <code>VirtualHost</code>.</p>
  229.  
  230.     <div class="note">
  231.           <h3>Note:</h3><p>On the internal
  232.           network, one can just use the name <code>server</code> rather
  233.           than the fully qualified host name
  234.           <code>server.example.com</code>.</p>
  235.  
  236.           <p>Note also that, in the above example, you can replace the list
  237.           of IP addresses with <code>*</code>, which will cause the server to
  238.           respond the same on all addresses.</p>
  239.     </div>
  240.  
  241.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  242. <div class="section">
  243. <h2><a name="port" id="port">Running different sites on different
  244.     ports.</a></h2>
  245.  
  246.     <p>You have multiple domains going to the same IP and also want to
  247.     serve multiple ports. By defining the ports in the "NameVirtualHost"
  248.     tag, you can allow this to work. If you try using <VirtualHost
  249.     name:port> without the NameVirtualHost name:port or you try to use
  250.     the Listen directive, your configuration will not work.</p>
  251.  
  252.     <div class="example"><h3>Server configuration</h3><p><code>
  253.     
  254.  
  255.     Listen 80<br />
  256.     Listen 8080<br />
  257.         <br />
  258.     NameVirtualHost 172.20.30.40:80<br />
  259.     NameVirtualHost 172.20.30.40:8080<br />
  260.         <br />
  261.     <VirtualHost 172.20.30.40:80><br />
  262.     <span class="indent">
  263.         ServerName www.example1.com<br />
  264.         DocumentRoot /www/domain-80<br />
  265.     </span>
  266.     </VirtualHost><br />
  267.         <br />
  268.     <VirtualHost 172.20.30.40:8080><br />
  269.     <span class="indent">
  270.         ServerName www.example1.com<br />
  271.         DocumentRoot /www/domain-8080<br />
  272.     </span>
  273.     </VirtualHost><br />
  274.         <br />
  275.     <VirtualHost 172.20.30.40:80><br />
  276.     <span class="indent">
  277.         ServerName www.example2.org<br />
  278.         DocumentRoot /www/otherdomain-80<br />
  279.     </span>
  280.     </VirtualHost><br />
  281.         <br />
  282.     <VirtualHost 172.20.30.40:8080><br />
  283.     <span class="indent">
  284.         ServerName www.example2.org<br />
  285.         DocumentRoot /www/otherdomain-8080<br />
  286.     </span>
  287.     </VirtualHost>
  288.     </code></p></div>
  289.  
  290.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  291. <div class="section">
  292. <h2><a name="ip" id="ip">IP-based virtual hosting</a></h2>
  293.  
  294.     <p>The server has two IP addresses (<code>172.20.30.40</code> and
  295.     <code>172.20.30.50</code>) which resolve to the names
  296.     <code>www.example1.com</code> and <code>www.example2.org</code>
  297.     respectively.</p>
  298.  
  299.     <div class="example"><h3>Server configuration</h3><p><code>
  300.     
  301.  
  302.     Listen 80<br />
  303.         <br />
  304.     <VirtualHost 172.20.30.40><br />
  305.     <span class="indent">
  306.         DocumentRoot /www/example1<br />
  307.         ServerName www.example1.com<br />
  308.     </span>
  309.     </VirtualHost><br />
  310.         <br />
  311.     <VirtualHost 172.20.30.50><br />
  312.     <span class="indent">
  313.         DocumentRoot /www/example2<br />
  314.         ServerName www.example2.org<br />
  315.     </span>
  316.     </VirtualHost>
  317.     </code></p></div>
  318.  
  319.     <p>Requests for any address not specified in one of the
  320.     <code><VirtualHost></code> directives (such as
  321.     <code>localhost</code>, for example) will go to the main server, if
  322.     there is one.</p>
  323.  
  324.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  325. <div class="section">
  326. <h2><a name="ipport" id="ipport">Mixed port-based and ip-based virtual
  327.     hosts</a></h2>
  328.  
  329.     <p>The server machine has two IP addresses (<code>172.20.30.40</code> and
  330.     <code>172.20.30.50</code>) which resolve to the names
  331.     <code>www.example1.com</code> and <code>www.example2.org</code>
  332.     respectively. In each case, we want to run hosts on ports 80 and
  333.     8080.</p>
  334.  
  335.     <div class="example"><h3>Server configuration</h3><p><code>
  336.     
  337.  
  338.     Listen 172.20.30.40:80<br />
  339.     Listen 172.20.30.40:8080<br />
  340.     Listen 172.20.30.50:80<br />
  341.     Listen 172.20.30.50:8080<br />
  342.         <br />
  343.     <VirtualHost 172.20.30.40:80><br />
  344.     <span class="indent">
  345.         DocumentRoot /www/example1-80<br />
  346.         ServerName www.example1.com<br />
  347.     </span>
  348.     </VirtualHost><br />
  349.         <br />
  350.     <VirtualHost 172.20.30.40:8080><br />
  351.     <span class="indent">
  352.         DocumentRoot /www/example1-8080<br />
  353.         ServerName www.example1.com<br />
  354.         </span>
  355.     </VirtualHost><br />
  356.         <br />
  357.     <VirtualHost 172.20.30.50:80><br />
  358.     <span class="indent">
  359.         DocumentRoot /www/example2-80<br />
  360.         ServerName www.example1.org<br />
  361.     </span>
  362.     </VirtualHost><br />
  363.         <br />
  364.     <VirtualHost 172.20.30.50:8080><br />
  365.     <span class="indent">
  366.         DocumentRoot /www/example2-8080<br />
  367.         ServerName www.example2.org<br />
  368.     </span>
  369.     </VirtualHost>
  370.     </code></p></div>
  371.  
  372.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  373. <div class="section">
  374. <h2><a name="mixed" id="mixed">Mixed name-based and IP-based
  375.     vhosts</a></h2>
  376.  
  377.     <p>On some of my addresses, I want to do name-based virtual hosts, and
  378.     on others, IP-based hosts.</p>
  379.  
  380.     <div class="example"><h3>Server configuration</h3><p><code>
  381.     
  382.  
  383.     Listen 80<br />
  384.         <br />
  385.     NameVirtualHost 172.20.30.40<br />
  386.         <br />
  387.     <VirtualHost 172.20.30.40><br />
  388.     <span class="indent">
  389.         DocumentRoot /www/example1<br />
  390.         ServerName www.example1.com<br />
  391.     </span>
  392.     </VirtualHost><br />
  393.         <br />
  394.     <VirtualHost 172.20.30.40><br />
  395.     <span class="indent">
  396.         DocumentRoot /www/example2<br />
  397.         ServerName www.example2.org<br />
  398.     </span>
  399.     </VirtualHost><br />
  400.         <br />
  401.     <VirtualHost 172.20.30.40><br />
  402.     <span class="indent">
  403.         DocumentRoot /www/example3<br />
  404.         ServerName www.example3.net<br />
  405.     </span>
  406.     </VirtualHost><br />
  407.         <br />
  408.     # IP-based<br />
  409.     <VirtualHost 172.20.30.50><br />
  410.     <span class="indent">
  411.         DocumentRoot /www/example4<br />
  412.         ServerName www.example4.edu<br />
  413.     </span>
  414.     </VirtualHost><br />
  415.         <br />
  416.     <VirtualHost 172.20.30.60><br />
  417.     <span class="indent">
  418.         DocumentRoot /www/example5<br />
  419.         ServerName www.example5.gov<br />
  420.     </span>
  421.     </VirtualHost>
  422.     </code></p></div>
  423.  
  424.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  425. <div class="section">
  426. <h2><a name="default" id="default">Using <code>_default_</code>
  427.     vhosts</a></h2>
  428.  
  429.       <h3><a name="defaultallports" id="defaultallports"><code>_default_</code> vhosts
  430.     for all ports</a></h3>
  431.  
  432.     <p>Catching <em>every</em> request to any unspecified IP address and
  433.     port, <em>i.e.</em>, an address/port combination that is not used for
  434.     any other virtual host.</p>
  435.  
  436.     <div class="example"><h3>Server configuration</h3><p><code>
  437.     
  438.  
  439.     <VirtualHost _default_:*><br />
  440.     <span class="indent">
  441.         DocumentRoot /www/default<br />
  442.     </span>
  443.     </VirtualHost>
  444.     </code></p></div>
  445.  
  446.     <p>Using such a default vhost with a wildcard port effectively prevents
  447.     any request going to the main server.</p>
  448.  
  449.     <p>A default vhost never serves a request that was sent to an
  450.     address/port that is used for name-based vhosts. If the request
  451.     contained an unknown or no <code>Host:</code> header it is always
  452.     served from the primary name-based vhost (the vhost for that
  453.     address/port appearing first in the configuration file).</p>
  454.  
  455.     <p>You can use <code class="directive"><a href="../mod/mod_alias.html#aliasmatch">AliasMatch</a></code> or
  456.     <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> to rewrite any
  457.     request to a single information page (or script).</p>
  458.     
  459.  
  460.     <h3><a name="defaultdifferentports" id="defaultdifferentports"><code>_default_</code> vhosts
  461.     for different ports</a></h3>
  462.  
  463.     <p>Same as setup 1, but the server listens on several ports and we want
  464.     to use a second <code>_default_</code> vhost for port 80.</p>
  465.  
  466.     <div class="example"><h3>Server configuration</h3><p><code>
  467.     
  468.  
  469.     <VirtualHost _default_:80><br />
  470.     <span class="indent">
  471.         DocumentRoot /www/default80<br />
  472.         # ...<br />
  473.     </span>
  474.     </VirtualHost><br />
  475.         <br />
  476.     <VirtualHost _default_:*><br />
  477.     <span class="indent">
  478.         DocumentRoot /www/default<br />
  479.         # ...<br />
  480.     </span>
  481.     </VirtualHost>
  482.     </code></p></div>
  483.  
  484.     <p>The default vhost for port 80 (which <em>must</em> appear before any
  485.     default vhost with a wildcard port) catches all requests that were sent
  486.     to an unspecified IP address. The main server is never used to serve a
  487.     request.</p>
  488.     
  489.  
  490.     <h3><a name="defaultoneport" id="defaultoneport"><code>_default_</code> vhosts
  491.     for one port</a></h3>
  492.  
  493.     <p>We want to have a default vhost for port 80, but no other default
  494.     vhosts.</p>
  495.  
  496.     <div class="example"><h3>Server configuration</h3><p><code>
  497.     
  498.  
  499.     <VirtualHost _default_:80><br />
  500.     DocumentRoot /www/default<br />
  501.     ...<br />
  502.     </VirtualHost>
  503.     </code></p></div>
  504.  
  505.     <p>A request to an unspecified address on port 80 is served from the
  506.     default vhost any other request to an unspecified address and port is
  507.     served from the main server.</p>
  508.     
  509.  
  510.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  511. <div class="section">
  512. <h2><a name="migrate" id="migrate">Migrating a name-based vhost to an
  513.     IP-based vhost</a></h2>
  514.  
  515.     <p>The name-based vhost with the hostname
  516.     <code>www.example2.org</code> (from our <a href="#name">name-based</a> example, setup 2) should get its own IP
  517.     address. To avoid problems with name servers or proxies who cached the
  518.     old IP address for the name-based vhost we want to provide both
  519.     variants during a migration phase.<br />
  520.      The solution is easy, because we can simply add the new IP address
  521.     (<code>172.20.30.50</code>) to the <code>VirtualHost</code>
  522.     directive.</p>
  523.  
  524.     <div class="example"><h3>Server configuration</h3><p><code>
  525.     
  526.  
  527.     Listen 80<br />
  528.     ServerName www.example1.com<br />
  529.     DocumentRoot /www/example1<br />
  530.         <br />
  531.     NameVirtualHost 172.20.30.40<br />
  532.         <br />
  533.     <VirtualHost 172.20.30.40 172.20.30.50><br />
  534.     <span class="indent">
  535.         DocumentRoot /www/example2<br />
  536.         ServerName www.example2.org<br />
  537.         # ...<br />
  538.     </span>
  539.     </VirtualHost><br />
  540.         <br />
  541.     <VirtualHost 172.20.30.40><br />
  542.     <span class="indent">
  543.         DocumentRoot /www/example3<br />
  544.         ServerName www.example3.net<br />
  545.         ServerAlias *.example3.net<br />
  546.         # ...<br />
  547.     </span>
  548.     </VirtualHost>
  549.     </code></p></div>
  550.  
  551.     <p>The vhost can now be accessed through the new address (as an
  552.     IP-based vhost) and through the old address (as a name-based
  553.     vhost).</p>
  554.  
  555.     </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
  556. <div class="section">
  557. <h2><a name="serverpath" id="serverpath">Using the <code>ServerPath</code>
  558.     directive</a></h2>
  559.  
  560.     <p>We have a server with two name-based vhosts. In order to match the
  561.     correct virtual host a client must send the correct <code>Host:</code>
  562.     header. Old HTTP/1.0 clients do not send such a header and Apache has
  563.     no clue what vhost the client tried to reach (and serves the request
  564.     from the primary vhost). To provide as much backward compatibility as
  565.     possible we create a primary vhost which returns a single page
  566.     containing links with an URL prefix to the name-based virtual
  567.     hosts.</p>
  568.  
  569.     <div class="example"><h3>Server configuration</h3><p><code>
  570.     
  571.  
  572.     NameVirtualHost 172.20.30.40<br />
  573.         <br />
  574.     <VirtualHost 172.20.30.40><br />
  575.     <span class="indent">
  576.         # primary vhost<br />
  577.         DocumentRoot /www/subdomain<br />
  578.         RewriteEngine On<br />
  579.         RewriteRule ^/.* /www/subdomain/index.html<br />
  580.         # ...<br />
  581.     </span>
  582.     </VirtualHost><br />
  583.         <br />
  584.     <VirtualHost 172.20.30.40><br />
  585.     DocumentRoot /www/subdomain/sub1<br />
  586.     <span class="indent">
  587.         ServerName www.sub1.domain.tld<br />
  588.         ServerPath /sub1/<br />
  589.         RewriteEngine On<br />
  590.         RewriteRule ^(/sub1/.*) /www/subdomain$1<br />
  591.         # ...<br />
  592.     </span>
  593.     </VirtualHost><br />
  594.         <br />
  595.     <VirtualHost 172.20.30.40><br />
  596.     <span class="indent">
  597.         DocumentRoot /www/subdomain/sub2<br />
  598.         ServerName www.sub2.domain.tld<br />
  599.         ServerPath /sub2/<br />
  600.         RewriteEngine On<br />
  601.         RewriteRule ^(/sub2/.*) /www/subdomain$1<br />
  602.         # ...<br />
  603.     </span>
  604.     </VirtualHost>
  605.     </code></p></div>
  606.  
  607.     <p>Due to the <code class="directive"><a href="../mod/core.html#serverpath">ServerPath</a></code>
  608.     directive a request to the URL
  609.     <code>http://www.sub1.domain.tld/sub1/</code> is <em>always</em> served
  610.     from the sub1-vhost.<br /> A request to the URL
  611.     <code>http://www.sub1.domain.tld/</code> is only
  612.     served from the sub1-vhost if the client sent a correct
  613.     <code>Host:</code> header. If no <code>Host:</code> header is sent the
  614.     client gets the information page from the primary host.<br />
  615.      Please note that there is one oddity: A request to
  616.     <code>http://www.sub2.domain.tld/sub1/</code> is also served from the
  617.     sub1-vhost if the client sent no <code>Host:</code> header.<br />
  618.      The <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> directives
  619.     are used to make sure that a client which sent a correct
  620.     <code>Host:</code> header can use both URL variants, <em>i.e.</em>,
  621.     with or without URL prefix.</p>
  622.  
  623.     </div></div>
  624. <div class="bottomlang">
  625. <p><span>Available Languages: </span><a href="../en/vhosts/examples.html" title="English"> en </a> |
  626. <a href="../ko/vhosts/examples.html" hreflang="ko" rel="alternate" title="Korean"> ko </a></p>
  627. </div><div id="footer">
  628. <p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</a></p>
  629. <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>
  630. </body></html>