examples.html.en revision c7811a175dc15d2172cc95f1c9791bbb6caf9b04
97a9a944b5887e91042b019776c41d5dd74557aferikabele<?xml version="1.0" encoding="ISO-8859-1"?>
97a9a944b5887e91042b019776c41d5dd74557aferikabele<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
97a9a944b5887e91042b019776c41d5dd74557aferikabele<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
b1ced323143ade589985456a78f3f64d6a6580c5yoshiki XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
b1ced323143ade589985456a78f3f64d6a6580c5yoshiki This file is generated from xml source: DO NOT EDIT
b1ced323143ade589985456a78f3f64d6a6580c5yoshiki XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd -->
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<title>VirtualHost Examples - Apache HTTP Server</title>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
2e545ce2450a9953665f701bb05350f0d3f26275nd<link href="/images/favicon.ico" rel="shortcut icon" /></head>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<body id="manual-page"><div id="page-header">
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen<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>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<p class="apache">Apache HTTP Server Version 2.1</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<img alt="" src="/images/feather.gif" /></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen<div id="path">
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<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-project/">Documentation</a> &gt; <a href="../">Version 2.1</a> &gt; <a href="./">Virtual Hosts</a></div><div id="page-content"><div id="preamble"><h1>VirtualHost Examples</h1>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="toplang">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<p><span>Available Languages: </span><a href="/en/vhosts/examples.html" title="English">&nbsp;en&nbsp;</a> |
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<a href="/ja/vhosts/examples.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<a href="/ko/vhosts/examples.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a></p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
7dc5a2d4a0c77f5bf5a95de92d68e43de7d8117anilgun <p>This document attempts to answer the commonly-asked questions about
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung setting up virtual hosts. These scenarios are those involving multiple
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd 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
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd coming soon about running sites on several servers behind a single
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd proxy server.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd</div>
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#purename">Running several name-based web
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd sites on a single IP address.</a></li>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<li><img alt="" src="/images/down.gif" /> <a href="#twoips">Name-based hosts on more than one
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf IP address.</a></li>
f19fa851b976a05691dea05be46586aa5aadeba2rbowen<li><img alt="" src="/images/down.gif" /> <a href="#intraextra">Serving the same content on
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf different IP addresses (such as an internal and external
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin address).</a></li>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin<li><img alt="" src="/images/down.gif" /> <a href="#port">Running different sites on different
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ports.</a></li>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf<li><img alt="" src="/images/down.gif" /> <a href="#ip">IP-based virtual hosting</a></li>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin<li><img alt="" src="/images/down.gif" /> <a href="#ipport">Mixed port-based and ip-based virtual
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf hosts</a></li>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin<li><img alt="" src="/images/down.gif" /> <a href="#mixed">Mixed name-based and IP-based
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin vhosts</a></li>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf<li><img alt="" src="/images/down.gif" /> <a href="#default">Using <code>_default_</code>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf vhosts</a></li>
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf<li><img alt="" src="/images/down.gif" /> <a href="#migrate">Migrating a name-based vhost to an
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf IP-based vhost</a></li>
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin<li><img alt="" src="/images/down.gif" /> <a href="#serverpath">Using the <code>ServerPath</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive directive</a></li>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen</ul></div>
f0a393c5c2d7de58f447855369ad2fbfa254e544rbowen<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<div class="section">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd<h2><a name="purename" id="purename">Running several name-based web
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd sites on a single IP address.</a></h2>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <p>Your server has a single IP address, and multiple aliases (CNAMES)
117c1f888a14e73cdd821dc6c23eb0411144a41cnd point to this machine in DNS. You want to run a web server for
117c1f888a14e73cdd821dc6c23eb0411144a41cnd <code>www.example.com</code> and <code>www.example.org</code> on this
117c1f888a14e73cdd821dc6c23eb0411144a41cnd machine.</p>
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <div class="note"><h3>Note</h3><p>Creating virtual
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf host configurations on your Apache server does not magically
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf cause DNS entries to be created for those host names. You
7571ea383299910bead3e93e66246cb212a28d0figalic <em>must</em> have the names in DNS, resolving to your IP
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh address, or nobody else will be able to see your web site. You
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf can put entries in your <code>hosts</code> file for local
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf testing, but that will work only from the machine with those
7571ea383299910bead3e93e66246cb212a28d0figalic hosts entries.</p>
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf </div>
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf <div class="example"><h3>Server configuration</h3><p><code>
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf # Ensure that Apache listens on port 80<br />
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf Listen 80<br />
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf <br />
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf # Listen for virtual host requests on all IP addresses<br />
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf NameVirtualHost *:80<br />
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf <br />
1f0a28764a0520e43ce3a9130e56236fd67cd568igalic &lt;VirtualHost *:80&gt;<br />
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf <span class="indent">
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf DocumentRoot /www/example1<br />
20f499565e77defe9dab24dd85c02f38a1175855nd ServerName www.example.com<br />
e487d6c09669296f94a5190cc34586a98e624a00nd <br />
f6445f3ad1c82f9398dc8edd77093cd3e20b806cnoirin # Other directives here<br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen <br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen </span>
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen &lt;/VirtualHost&gt;<br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen <br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen &lt;VirtualHost *:80&gt;<br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen <span class="indent">
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen DocumentRoot /www/example2<br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen ServerName www.example.org<br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen <br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen # Other directives here<br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen <br />
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen </span>
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen &lt;/VirtualHost&gt;
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen </code></p></div>
9b3696c7ad70387ecd46e0f061b99d381dc392f9rbowen
b41a0dbe6310c576e96b7ea6910051fd84fb06f5sf <p>The asterisks match all addresses, so the main server serves no
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd requests. Due to the fact that <code>www.example.com</code> is first
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd in the configuration file, it has the highest priority and can be seen
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd as the <cite>default</cite> or <cite>primary</cite> server. That means
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd that if a request is received that does not match one of the specified
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <code>ServerName</code> directives, it will be served by this first
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin <code>VirtualHost</code>.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <div class="note">
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <h3>Note</h3>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <p>You can, if you wish, replace <code>*</code> with the actual
06f0540592b1d6fc148e1ec9afc95ce48162db18covener IP address of the system. In that case, the argument to
06f0540592b1d6fc148e1ec9afc95ce48162db18covener <code>VirtualHost</code> <em>must</em> match the argument to
06f0540592b1d6fc148e1ec9afc95ce48162db18covener <code>NameVirtualHost</code>:</p>
06f0540592b1d6fc148e1ec9afc95ce48162db18covener
06f0540592b1d6fc148e1ec9afc95ce48162db18covener <div class="example"><p><code>
06f0540592b1d6fc148e1ec9afc95ce48162db18covener NameVirtualHost 172.20.30.40<br />
b9bf3918f6eaf7747bcbfbd02792bcbe4a052784nilgun <br />
06f0540592b1d6fc148e1ec9afc95ce48162db18covener &lt;VirtualHost 172.20.30.40&gt;<br />
06f0540592b1d6fc148e1ec9afc95ce48162db18covener # etc ...
06f0540592b1d6fc148e1ec9afc95ce48162db18covener </code></p></div>
06f0540592b1d6fc148e1ec9afc95ce48162db18covener
06f0540592b1d6fc148e1ec9afc95ce48162db18covener <p>However, it is additionally useful to use <code>*</code>
06f0540592b1d6fc148e1ec9afc95ce48162db18covener on systems where the IP address is not predictable - for
06f0540592b1d6fc148e1ec9afc95ce48162db18covener example if you have a dynamic IP address with your ISP, and
06f0540592b1d6fc148e1ec9afc95ce48162db18covener you are using some variety of dynamic DNS solution. Since
06f0540592b1d6fc148e1ec9afc95ce48162db18covener <code>*</code> matches any IP address, this configuration
06f0540592b1d6fc148e1ec9afc95ce48162db18covener would work without changes whenever your IP address
635de20c16ef862bfc5b0d5f9ceb40ebeaddfdf3noirin changes.</p>
06f0540592b1d6fc148e1ec9afc95ce48162db18covener </div>
06f0540592b1d6fc148e1ec9afc95ce48162db18covener
06f0540592b1d6fc148e1ec9afc95ce48162db18covener <p>The above configuration is what you will want to use in almost
06f0540592b1d6fc148e1ec9afc95ce48162db18covener all name-based virtual hosting situations. The only thing that this
06f0540592b1d6fc148e1ec9afc95ce48162db18covener configuration will not work for, in fact, is when you are serving
4aa603e6448b99f9371397d439795c91a93637eand different content based on differing IP addresses or ports.</p>
06f0540592b1d6fc148e1ec9afc95ce48162db18covener
06f0540592b1d6fc148e1ec9afc95ce48162db18covener </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
17ade6df5ec233536985eb1c130a906c725dd614humbedooh<div class="section">
17ade6df5ec233536985eb1c130a906c725dd614humbedooh<h2><a name="twoips" id="twoips">Name-based hosts on more than one
17ade6df5ec233536985eb1c130a906c725dd614humbedooh IP address.</a></h2>
4aa603e6448b99f9371397d439795c91a93637eand
17ade6df5ec233536985eb1c130a906c725dd614humbedooh <div class="note">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <h3>Note</h3><p>Any of the
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd techniques discussed here can be extended to any number of IP
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd addresses.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd </div>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <p>The server has two IP addresses. On one (<code>172.20.30.40</code>), we
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd will serve the "main" server, <code>server.domain.com</code> and on the
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd other (<code>172.20.30.50</code>), we will serve two or more virtual hosts.</p>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <div class="example"><h3>Server configuration</h3><p><code>
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd Listen 80<br />
0c4abc32c00611fe1d52c9661f5cc79a3f74c6d4nd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd # This is the "main" server running on 172.20.30.40<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd ServerName server.domain.com<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd DocumentRoot /www/mainserver<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd # This is the other address<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd NameVirtualHost 172.20.30.50<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;VirtualHost 172.20.30.50&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <span class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DocumentRoot /www/example1<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ServerName www.example.com<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem # Other directives here ...<br />
b115299831a7b4bbec58a88d708d8536e1ecd50csf <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd </span>
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;/VirtualHost&gt;<br />
b115299831a7b4bbec58a88d708d8536e1ecd50csf <br />
b115299831a7b4bbec58a88d708d8536e1ecd50csf &lt;VirtualHost 172.20.30.50&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <span class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DocumentRoot /www/example2<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ServerName www.example.org<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <br />
b115299831a7b4bbec58a88d708d8536e1ecd50csf # Other directives here ...<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd </span>
b115299831a7b4bbec58a88d708d8536e1ecd50csf &lt;/VirtualHost&gt;
b115299831a7b4bbec58a88d708d8536e1ecd50csf </code></p></div>
fa0f379e3845907d7c1087d885169e302239bdbbnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Any request to an address other than <code>172.20.30.50</code> will be
06ba4a61654b3763ad65f52283832ebf058fdf1cslive served from the main server. A request to <code>172.20.30.50</code> with an
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem unknown hostname, or no <code>Host:</code> header, will be served from
fa0f379e3845907d7c1087d885169e302239bdbbnd <code>www.example.com</code>.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<div class="section">
fa0f379e3845907d7c1087d885169e302239bdbbnd<h2><a name="intraextra" id="intraextra">Serving the same content on
81785f72c9d133aef57ad6b02f248345d90239aapoirier different IP addresses (such as an internal and external
fa0f379e3845907d7c1087d885169e302239bdbbnd address).</a></h2>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>The server machine has two IP addresses (<code>192.168.1.1</code>
fa0f379e3845907d7c1087d885169e302239bdbbnd and <code>172.20.30.40</code>). The machine is sitting between an
fa0f379e3845907d7c1087d885169e302239bdbbnd internal (intranet) network and an external (internet) network. Outside
fa0f379e3845907d7c1087d885169e302239bdbbnd of the network, the name <code>server.example.com</code> resolves to
c6a2d6fa44f8698851dec5051ee3782c2913605fnd the external address (<code>172.20.30.40</code>), but inside the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive network, that same name resolves to the internal address
97a9a944b5887e91042b019776c41d5dd74557aferikabele (<code>192.168.1.1</code>).</p>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p>The server can be made to respond to internal and external requests
97a9a944b5887e91042b019776c41d5dd74557aferikabele with the same content, with just one <code>VirtualHost</code>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi section.</p>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi
97a9a944b5887e91042b019776c41d5dd74557aferikabele <div class="example"><h3>Server configuration</h3><p><code>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele NameVirtualHost 192.168.1.1<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele NameVirtualHost 172.20.30.40<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele <br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive &lt;VirtualHost 192.168.1.1 172.20.30.40&gt;<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <span class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DocumentRoot /www/server1<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele ServerName server.example.com<br />
1b9c57e74f282283966fa424192df142595338bdnd ServerAlias server<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele </span>
74a6de79356cd15d2e47065087785e36dd65aa41nd &lt;/VirtualHost&gt;
97a9a944b5887e91042b019776c41d5dd74557aferikabele </code></p></div>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p>Now requests from both networks will be served from the same
97a9a944b5887e91042b019776c41d5dd74557aferikabele <code>VirtualHost</code>.</p>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele <div class="note">
97a9a944b5887e91042b019776c41d5dd74557aferikabele <h3>Note:</h3><p>On the internal
06ba4a61654b3763ad65f52283832ebf058fdf1cslive network, one can just use the name <code>server</code> rather
5ae30adbe59946de742ab0cd6be3b7457471a698takashi than the fully qualified host name
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <code>server.example.com</code>.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Note also that, in the above example, you can replace the list
06ba4a61654b3763ad65f52283832ebf058fdf1cslive of IP addresses with <code>*</code>, which will cause the server to
53d2fd50ff45e7c568f0588c742a5ef9edf8e275rbowen respond the same on all addresses.</p>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi<div class="section">
5ae30adbe59946de742ab0cd6be3b7457471a698takashi<h2><a name="port" id="port">Running different sites on different
97a9a944b5887e91042b019776c41d5dd74557aferikabele ports.</a></h2>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p>You have multiple domains going to the same IP and also want to
97a9a944b5887e91042b019776c41d5dd74557aferikabele serve multiple ports. By defining the ports in the "NameVirtualHost"
97a9a944b5887e91042b019776c41d5dd74557aferikabele tag, you can allow this to work. If you try using &lt;VirtualHost
97a9a944b5887e91042b019776c41d5dd74557aferikabele name:port&gt; without the NameVirtualHost name:port or you try to use
06ba4a61654b3763ad65f52283832ebf058fdf1cslive the Listen directive, your configuration will not work.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <div class="example"><h3>Server configuration</h3><p><code>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabele Listen 80<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele Listen 8080<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele <br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele NameVirtualHost 172.20.30.40:80<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele NameVirtualHost 172.20.30.40:8080<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele <br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive &lt;VirtualHost 172.20.30.40:80&gt;<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <span class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ServerName www.example.com<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele DocumentRoot /www/domain-80<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele </span>
97a9a944b5887e91042b019776c41d5dd74557aferikabele &lt;/VirtualHost&gt;<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele <br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele &lt;VirtualHost 172.20.30.40:8080&gt;<br />
fb82af0f0cd7b58eef19c54b086131b7e1e1e749madhum <span class="indent">
4203a35c28d7c60adb7e9ef3be87aad34951c79asf ServerName www.example.com<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DocumentRoot /www/domain-8080<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </span>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive &lt;/VirtualHost&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;VirtualHost 172.20.30.40:80&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <span class="indent">
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen ServerName www.example.org<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd DocumentRoot /www/otherdomain-80<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd </span>
37ef4b86270a8e58f87aa5fe558e3e65af97991ccovener &lt;/VirtualHost&gt;<br />
37ef4b86270a8e58f87aa5fe558e3e65af97991ccovener <br />
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf &lt;VirtualHost 172.20.30.40:8080&gt;<br />
37ef4b86270a8e58f87aa5fe558e3e65af97991ccovener <span class="indent">
37ef4b86270a8e58f87aa5fe558e3e65af97991ccovener ServerName www.example.org<br />
37ef4b86270a8e58f87aa5fe558e3e65af97991ccovener DocumentRoot /www/otherdomain-8080<br />
37ef4b86270a8e58f87aa5fe558e3e65af97991ccovener </span>
37ef4b86270a8e58f87aa5fe558e3e65af97991ccovener &lt;/VirtualHost&gt;
fa0f379e3845907d7c1087d885169e302239bdbbnd </code></p></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<div class="section">
fa0f379e3845907d7c1087d885169e302239bdbbnd<h2><a name="ip" id="ip">IP-based virtual hosting</a></h2>
fa0f379e3845907d7c1087d885169e302239bdbbnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>The server has two IP addresses (<code>172.20.30.40</code> and
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>172.20.30.50</code>) which resolve to the names
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>www.example.com</code> and <code>www.example.org</code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive respectively.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <div class="example"><h3>Server configuration</h3><p><code>
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd Listen 80<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen &lt;VirtualHost 172.20.30.40&gt;<br />
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen <span class="indent">
fa0f379e3845907d7c1087d885169e302239bdbbnd DocumentRoot /www/example1<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd ServerName www.example.com<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </span>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive &lt;/VirtualHost&gt;<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive &lt;VirtualHost 172.20.30.50&gt;<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <span class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DocumentRoot /www/example2<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ServerName www.example.org<br />
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf </span>
777c17c11c2b1638f191241364e034779851d186covener &lt;/VirtualHost&gt;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </code></p></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Requests for any address not specified in one of the
0844fff26cb7719e0f0a368d88544156ed6374b6sf <code>&lt;VirtualHost&gt;</code> directives (such as
0844fff26cb7719e0f0a368d88544156ed6374b6sf <code>localhost</code>, for example) will go to the main server, if
0844fff26cb7719e0f0a368d88544156ed6374b6sf there is one.</p>
0844fff26cb7719e0f0a368d88544156ed6374b6sf
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<div class="section">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<h2><a name="ipport" id="ipport">Mixed port-based and ip-based virtual
fa0f379e3845907d7c1087d885169e302239bdbbnd hosts</a></h2>
c0a201f9f0cda37f4e5829462c7e489f85bf327ccovener
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <p>The server machine has two IP addresses (<code>172.20.30.40</code> and
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <code>172.20.30.50</code>) which resolve to the names
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf <code>www.example.com</code> and <code>www.example.org</code>
15a7e433cd5ddbb53d48a11f2f8732d9ea6a48caminfrin respectively. In each case, we want to run hosts on ports 80 and
15a7e433cd5ddbb53d48a11f2f8732d9ea6a48caminfrin 8080.</p>
15a7e433cd5ddbb53d48a11f2f8732d9ea6a48caminfrin
15a7e433cd5ddbb53d48a11f2f8732d9ea6a48caminfrin <div class="example"><h3>Server configuration</h3><p><code>
15a7e433cd5ddbb53d48a11f2f8732d9ea6a48caminfrin
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd Listen 172.20.30.40:80<br />
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd Listen 172.20.30.40:8080<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd Listen 172.20.30.50:80<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd Listen 172.20.30.50:8080<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;VirtualHost 172.20.30.40:80&gt;<br />
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd <span class="indent">
4203a35c28d7c60adb7e9ef3be87aad34951c79asf DocumentRoot /www/example1-80<br />
4203a35c28d7c60adb7e9ef3be87aad34951c79asf ServerName www.example.com<br />
4eafd186275d2df6e74aaa778a57b24a6c725e49humbedooh </span>
4203a35c28d7c60adb7e9ef3be87aad34951c79asf &lt;/VirtualHost&gt;<br />
4203a35c28d7c60adb7e9ef3be87aad34951c79asf <br />
4203a35c28d7c60adb7e9ef3be87aad34951c79asf &lt;VirtualHost 172.20.30.40:8080&gt;<br />
1b9c57e74f282283966fa424192df142595338bdnd <span class="indent">
1b9c57e74f282283966fa424192df142595338bdnd DocumentRoot /www/example1-8080<br />
1b9c57e74f282283966fa424192df142595338bdnd ServerName www.example.com<br />
1b9c57e74f282283966fa424192df142595338bdnd </span>
1b9c57e74f282283966fa424192df142595338bdnd &lt;/VirtualHost&gt;<br />
1b9c57e74f282283966fa424192df142595338bdnd <br />
1b9c57e74f282283966fa424192df142595338bdnd &lt;VirtualHost 172.20.30.50:80&gt;<br />
1b9c57e74f282283966fa424192df142595338bdnd <span class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DocumentRoot /www/example2-80<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele ServerName www.example.org<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd </span>
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;/VirtualHost&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
c11bfe6804eff2f4c7054cf2f7b06f0c8b32e596sf &lt;VirtualHost 172.20.30.50:8080&gt;<br />
c11bfe6804eff2f4c7054cf2f7b06f0c8b32e596sf <span class="indent">
c11bfe6804eff2f4c7054cf2f7b06f0c8b32e596sf DocumentRoot /www/example2-8080<br />
c11bfe6804eff2f4c7054cf2f7b06f0c8b32e596sf ServerName www.example.org<br />
c11bfe6804eff2f4c7054cf2f7b06f0c8b32e596sf </span>
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf &lt;/VirtualHost&gt;
fa0f379e3845907d7c1087d885169e302239bdbbnd </code></p></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fa0f379e3845907d7c1087d885169e302239bdbbnd </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fa0f379e3845907d7c1087d885169e302239bdbbnd<div class="section">
fa0f379e3845907d7c1087d885169e302239bdbbnd<h2><a name="mixed" id="mixed">Mixed name-based and IP-based
fa0f379e3845907d7c1087d885169e302239bdbbnd vhosts</a></h2>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen <p>On some of my addresses, I want to do name-based virtual hosts, and
fa0f379e3845907d7c1087d885169e302239bdbbnd on others, IP-based hosts.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <div class="example"><h3>Server configuration</h3><p><code>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd Listen 80<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd NameVirtualHost 172.20.30.40<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;VirtualHost 172.20.30.40&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <span class="indent">
fa0f379e3845907d7c1087d885169e302239bdbbnd DocumentRoot /www/example1<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd ServerName www.example.com<br />
a4d04b8c74044c58bd4182028a1408d936c95951covener </span>
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;/VirtualHost&gt;<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;VirtualHost 172.20.30.40&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <span class="indent">
fa0f379e3845907d7c1087d885169e302239bdbbnd DocumentRoot /www/example2<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd ServerName www.example.org<br />
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen </span>
cea021a7fc2657b091df4d3b031c4254ec371dd7rbowen &lt;/VirtualHost&gt;<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem &lt;VirtualHost 172.20.30.40&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <span class="indent">
eaaa852423e42d6d86bcada80ed781a205fc3e5fnd DocumentRoot /www/example3<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd ServerName www.example3.net<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd </span>
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;/VirtualHost&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd # IP-based<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;VirtualHost 172.20.30.50&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <span class="indent">
fa0f379e3845907d7c1087d885169e302239bdbbnd DocumentRoot /www/example4<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd ServerName www.example4.edu<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd </span>
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;/VirtualHost&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <br />
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;VirtualHost 172.20.30.60&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <span class="indent">
fa0f379e3845907d7c1087d885169e302239bdbbnd DocumentRoot /www/example5<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd ServerName www.example5.gov<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd </span>
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;/VirtualHost&gt;
fa0f379e3845907d7c1087d885169e302239bdbbnd </code></p></div>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
fa0f379e3845907d7c1087d885169e302239bdbbnd<div class="section">
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem<h2><a name="default" id="default">Using <code>_default_</code>
025dc11c0fd8d6a7fdb5f0a46cc3a5fbab64b93drbowen vhosts</a></h2>
025dc11c0fd8d6a7fdb5f0a46cc3a5fbab64b93drbowen
fa0f379e3845907d7c1087d885169e302239bdbbnd <h3><a name="defaultallports" id="defaultallports"><code>_default_</code> vhosts
fa0f379e3845907d7c1087d885169e302239bdbbnd for all ports</a></h3>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>Catching <em>every</em> request to any unspecified IP address and
fa0f379e3845907d7c1087d885169e302239bdbbnd port, <em>i.e.</em>, an address/port combination that is not used for
fa0f379e3845907d7c1087d885169e302239bdbbnd any other virtual host.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <div class="example"><h3>Server configuration</h3><p><code>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;VirtualHost _default_:*&gt;<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd <span class="indent">
fa0f379e3845907d7c1087d885169e302239bdbbnd DocumentRoot /www/default<br />
fa0f379e3845907d7c1087d885169e302239bdbbnd </span>
fa0f379e3845907d7c1087d885169e302239bdbbnd &lt;/VirtualHost&gt;
fa0f379e3845907d7c1087d885169e302239bdbbnd </code></p></div>
fa0f379e3845907d7c1087d885169e302239bdbbnd
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>Using such a default vhost with a wildcard port effectively prevents
fa0f379e3845907d7c1087d885169e302239bdbbnd any request going to the main server.</p>
fa0f379e3845907d7c1087d885169e302239bdbbnd
fa0f379e3845907d7c1087d885169e302239bdbbnd <p>A default vhost never serves a request that was sent to an
fa0f379e3845907d7c1087d885169e302239bdbbnd address/port that is used for name-based vhosts. If the request
fa0f379e3845907d7c1087d885169e302239bdbbnd contained an unknown or no <code>Host:</code> header it is always
06ba4a61654b3763ad65f52283832ebf058fdf1cslive served from the primary name-based vhost (the vhost for that
06ba4a61654b3763ad65f52283832ebf058fdf1cslive address/port appearing first in the configuration file).</p>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>You can use <code class="directive"><a href="/mod/mod_alias.html#aliasmatch">AliasMatch</a></code> or
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> to rewrite any
06ba4a61654b3763ad65f52283832ebf058fdf1cslive request to a single information page (or script).</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
88f586e767b7b224bdb1a178455668a2475cfc75rbowen
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <h3><a name="defaultdifferentports" id="defaultdifferentports"><code>_default_</code> vhosts
88f586e767b7b224bdb1a178455668a2475cfc75rbowen for different ports</a></h3>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <p>Same as setup 1, but the server listens on several ports and we want
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to use a second <code>_default_</code> vhost for port 80.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <div class="example"><h3>Server configuration</h3><p><code>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive &lt;VirtualHost _default_:80&gt;<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <span class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DocumentRoot /www/default80<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive # ...<br />
81785f72c9d133aef57ad6b02f248345d90239aapoirier </span>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi &lt;/VirtualHost&gt;<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem &lt;VirtualHost _default_:*&gt;<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <span class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DocumentRoot /www/default<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive # ...<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem </span>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem &lt;/VirtualHost&gt;
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem </code></p></div>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>The default vhost for port 80 (which <em>must</em> appear before any
06ba4a61654b3763ad65f52283832ebf058fdf1cslive default vhost with a wildcard port) catches all requests that were sent
06ba4a61654b3763ad65f52283832ebf058fdf1cslive to an unspecified IP address. The main server is never used to serve a
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem request.</p>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <h3><a name="defaultoneport" id="defaultoneport"><code>_default_</code> vhosts
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem for one port</a></h3>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>We want to have a default vhost for port 80, but no other default
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem vhosts.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <div class="example"><h3>Server configuration</h3><p><code>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen &lt;VirtualHost _default_:80&gt;<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen DocumentRoot /www/default<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen ...<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen &lt;/VirtualHost&gt;
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen </code></p></div>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <p>A request to an unspecified address on port 80 is served from the
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen default vhost. Any other request to an unspecified address and port is
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen served from the main server.</p>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen<div class="section">
88f586e767b7b224bdb1a178455668a2475cfc75rbowen<h2><a name="migrate" id="migrate">Migrating a name-based vhost to an
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen IP-based vhost</a></h2>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <p>The name-based vhost with the hostname
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <code>www.example.org</code> (from our <a href="#name">name-based</a> example, setup 2) should get its own IP
88f586e767b7b224bdb1a178455668a2475cfc75rbowen address. To avoid problems with name servers or proxies who cached the
88f586e767b7b224bdb1a178455668a2475cfc75rbowen old IP address for the name-based vhost we want to provide both
88f586e767b7b224bdb1a178455668a2475cfc75rbowen variants during a migration phase.</p>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <p>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen The solution is easy, because we can simply add the new IP address
88f586e767b7b224bdb1a178455668a2475cfc75rbowen (<code>172.20.30.50</code>) to the <code>VirtualHost</code>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen directive.</p>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <div class="example"><h3>Server configuration</h3><p><code>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen
88f586e767b7b224bdb1a178455668a2475cfc75rbowen
88f586e767b7b224bdb1a178455668a2475cfc75rbowen Listen 80<br />
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ServerName www.example.com<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen DocumentRoot /www/example1<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen NameVirtualHost 172.20.30.40<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen &lt;VirtualHost 172.20.30.40 172.20.30.50&gt;<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <span class="indent">
88f586e767b7b224bdb1a178455668a2475cfc75rbowen DocumentRoot /www/example2<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen ServerName www.example.org<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen # ...<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen </span>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen &lt;/VirtualHost&gt;<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen &lt;VirtualHost 172.20.30.40&gt;<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <span class="indent">
88f586e767b7b224bdb1a178455668a2475cfc75rbowen DocumentRoot /www/example3<br />
9a58dc6a2b26ec128b1270cf48810e705f1a90dbsf ServerName www.example.net<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen ServerAlias *.example.net<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen # ...<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen </span>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen &lt;/VirtualHost&gt;
88f586e767b7b224bdb1a178455668a2475cfc75rbowen </code></p></div>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <p>The vhost can now be accessed through the new address (as an
88f586e767b7b224bdb1a178455668a2475cfc75rbowen IP-based vhost) and through the old address (as a name-based
88f586e767b7b224bdb1a178455668a2475cfc75rbowen vhost).</p>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen
88f586e767b7b224bdb1a178455668a2475cfc75rbowen </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen<div class="section">
88f586e767b7b224bdb1a178455668a2475cfc75rbowen<h2><a name="serverpath" id="serverpath">Using the <code>ServerPath</code>
88f586e767b7b224bdb1a178455668a2475cfc75rbowen directive</a></h2>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
97a9a944b5887e91042b019776c41d5dd74557aferikabele <p>We have a server with two name-based vhosts. In order to match the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive correct virtual host a client must send the correct <code>Host:</code>
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem header. Old HTTP/1.0 clients do not send such a header and Apache has
06ba4a61654b3763ad65f52283832ebf058fdf1cslive no clue what vhost the client tried to reach (and serves the request
06ba4a61654b3763ad65f52283832ebf058fdf1cslive from the primary vhost). To provide as much backward compatibility as
97a9a944b5887e91042b019776c41d5dd74557aferikabele possible we create a primary vhost which returns a single page
06ba4a61654b3763ad65f52283832ebf058fdf1cslive containing links with an URL prefix to the name-based virtual
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem hosts.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <div class="example"><h3>Server configuration</h3><p><code>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem
06ba4a61654b3763ad65f52283832ebf058fdf1cslive NameVirtualHost 172.20.30.40<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem &lt;VirtualHost 172.20.30.40&gt;<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <span class="indent">
06ba4a61654b3763ad65f52283832ebf058fdf1cslive # primary vhost<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen DocumentRoot /www/subdomain<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen RewriteEngine On<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen RewriteRule ^/.* /www/subdomain/index.html<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen # ...<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen </span>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen &lt;/VirtualHost&gt;<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen &lt;VirtualHost 172.20.30.40&gt;<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen DocumentRoot /www/subdomain/sub1<br />
88f586e767b7b224bdb1a178455668a2475cfc75rbowen <span class="indent">
88f586e767b7b224bdb1a178455668a2475cfc75rbowen ServerName www.sub1.domain.tld<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen ServerPath /sub1/<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen RewriteEngine On<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen RewriteRule ^(/sub1/.*) /www/subdomain$1<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen # ...<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen </span>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen &lt;/VirtualHost&gt;<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen &lt;VirtualHost 172.20.30.40&gt;<br />
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <span class="indent">
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen DocumentRoot /www/subdomain/sub2<br />
b0ffb6279db3bd422faeff9a59a43dc762afe148minfrin ServerName www.sub2.domain.tld<br />
97a9a944b5887e91042b019776c41d5dd74557aferikabele ServerPath /sub2/<br />
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem RewriteEngine On<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive RewriteRule ^(/sub2/.*) /www/subdomain$1<br />
06ba4a61654b3763ad65f52283832ebf058fdf1cslive # ...<br />
81785f72c9d133aef57ad6b02f248345d90239aapoirier </span>
b0ffb6279db3bd422faeff9a59a43dc762afe148minfrin &lt;/VirtualHost&gt;
b0ffb6279db3bd422faeff9a59a43dc762afe148minfrin </code></p></div>
b0ffb6279db3bd422faeff9a59a43dc762afe148minfrin
b0ffb6279db3bd422faeff9a59a43dc762afe148minfrin <p>Due to the <code class="directive"><a href="/mod/core.html#serverpath">ServerPath</a></code>
b0ffb6279db3bd422faeff9a59a43dc762afe148minfrin directive a request to the URL
b0ffb6279db3bd422faeff9a59a43dc762afe148minfrin <code>http://www.sub1.domain.tld/sub1/</code> is <em>always</em> served
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen from the sub1-vhost.<br /> A request to the URL
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <code>http://www.sub1.domain.tld/</code> is only
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen served from the sub1-vhost if the client sent a correct
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <code>Host:</code> header. If no <code>Host:</code> header is sent the
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen client gets the information page from the primary host.</p>
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <p>Please note that there is one oddity: A request to
3b1807171c3f06d8951da1bf23c5f51961c274bbrbowen <code>http://www.sub2.domain.tld/sub1/</code> is also served from the
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sub1-vhost if the client sent no <code>Host:</code> header.</p>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
bf380c59be3f235bde21f1c00098e09e3cf7e7aerpluem <p>The <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> directives
06ba4a61654b3763ad65f52283832ebf058fdf1cslive are used to make sure that a client which sent a correct
06ba4a61654b3763ad65f52283832ebf058fdf1cslive <code>Host:</code> header can use both URL variants, <em>i.e.</em>,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive with or without URL prefix.</p>
97a9a944b5887e91042b019776c41d5dd74557aferikabele
06ba4a61654b3763ad65f52283832ebf058fdf1cslive </div></div>
06ba4a61654b3763ad65f52283832ebf058fdf1cslive<div class="bottomlang">
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf<p><span>Available Languages: </span><a href="/en/vhosts/examples.html" title="English">&nbsp;en&nbsp;</a> |
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf<a href="/ja/vhosts/examples.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
c0c1f9ffbf550e6ba5e60d2d0ee55490794f3aefrbowen<a href="/ko/vhosts/examples.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a></p>
4cb65c31bc681540ea623e1cb2bdd09749fb8d7esf</div><div id="footer">
fa1092e17f0b85a610379ac564334ad879ed7dbarbowen<p class="apache">Copyright 1999-2004 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>
fa1092e17f0b85a610379ac564334ad879ed7dbarbowen<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>
fa1092e17f0b85a610379ac564334ad879ed7dbarbowen</body></html>