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