<tr>
<td bgcolor="#eeeeee">
<pre>
- NameVirtualHost 12.34.56.78
- <VirtualHost 12.34.56.78>
+ NameVirtualHost 172.20.30.40
+
+ <VirtualHost 172.20.30.40>
# etc ...
</pre>
</td>
</blockquote>
<strong>Setup 1:</strong>
- <p>The server has two IP addresses. On one (<samp>1.2.3.4</samp>), we
- will serve the "main" server, and on the other (<samp>5.6.7.8</samp>),
- we will serve two or more virtual hosts.</p>
+ <p>The server has two IP addresses. On one (<samp>172.20.30.40</samp>), we
+ will serve the "main" server, <samp>server.domain.com</samp> and on the
+ other (<samp>172.20.30.50</samp>), we will serve two or more virtual hosts.</p>
<p><strong>Server configuration:</strong></p>
<pre>
Listen 80
- # This is the "main" server
+ # This is the "main" server running on 172.20.30.40
ServerName server.domain.com
DocumentRoot /www/mainserver
# This is the other address
- NameVirtualHost 5.6.7.8
+ NameVirtualHost 172.20.30.50
- <VirtualHost 5.6.7.8>
+ <VirtualHost 172.20.30.50>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>
- <VirtualHost 5.6.7.8>
+ <VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example2.org
</table>
</blockquote>
- <p>Any request to an address other than <samp>5.6.7.8</samp> will be
- served from the main server. A request to <samp>5.6.7.8</samp> with an
+ <p>Any request to an address other than <samp>172.20.30.50</samp> will be
+ served from the main server. A request to <samp>172.20.30.50</samp> with an
unknown hostname, or no <code>Host:</code> header, will be served from
<samp>www.example1.com</samp>.</p>
<strong>Setup:</strong>
<p>The server machine has two IP addresses (<samp>192.168.1.1</samp>
- and <samp>11.22.33.44</samp>). The machine is sitting between an
+ and <samp>172.20.30.40</samp>). The machine is sitting between an
internal (intranet) network and an external (internet) network. Outside
of the network, the name <samp>server.example.com</samp> resolves to
- the external address (<samp>111.22.33.55</samp>), but inside the
+ the external address (<samp>172.20.30.40</samp>), but inside the
network, that same name resolves to the internal address
(<samp>192.168.1.1</samp>).</p>
<td bgcolor="#eeeeee">
<pre>
NameVirtualHost 192.168.1.1
- NameVirtualHost 11.22.33.44
+ NameVirtualHost 172.20.30.40
- <VirtualHost 192.168.1.1 11.22.33.44>
+ <VirtualHost 192.168.1.1 172.20.30.40>
DocumentRoot /www/server1
ServerName server.example.com
ServerAlias server
<blockquote>
<table>
<tr>
- <td bgcolor="#e0e5f5"><strong>Note:</strong> On the internal
+ <td bgcolor="#e0e5f5">
+
+ <p><strong>Note:</strong> On the internal
network, one can just use the name <code>server</code> rather
- than the fully qualified host name <code>server.example.com. Note
- also that, in the above example, you can replace the list of IP
- addresses with</code> *, which will cause the server to respond
- the same on all addresses.</td>
+ than the fully qualified host name
+ <code>server.example.com</code>.</p>
+
+ <p>Note also that, in the above example, you can replace the list
+ of IP addresses with <code>*</code>, which will cause the server to
+ respond the same on all addresses.</p>
+
+ </td>
</tr>
</table>
</blockquote>
Listen 80
Listen 8080
- NameVirtualHost 11.22.33.44:80
- NameVirtualHost 11.22.33.44:8080
+ NameVirtualHost 172.20.30.40:80
+ NameVirtualHost 172.20.30.40:8080
- <VirtualHost 11.22.33.44:80>
- ServerName www.domain.tld
+ <VirtualHost 172.20.30.40:80>
+ ServerName www.example1.com
DocumentRoot /www/domain-80
</VirtualHost>
- <VirtualHost 11.22.33.44:8080>
- ServerName www.domain.tld
+ <VirtualHost 172.20.30.40:8080>
+ ServerName www.example1.com
DocumentRoot /www/domain-8080
</VirtualHost>
- <VirtualHost 11.22.33.44:80>
- ServerName www.otherdomain.tld
+ <VirtualHost 172.20.30.40:80>
+ ServerName www.example2.org
DocumentRoot /www/otherdomain-80
</VirtualHost>
- <VirtualHost 11.22.33.44:8080>
- ServerName www.otherdomain.tld
+ <VirtualHost 172.20.30.40:8080>
+ ServerName www.example2.org
DocumentRoot /www/otherdomain-8080
</VirtualHost>
</pre>
<p><strong>Setup:</strong></p>
- <p>The server has two IP addresses (<samp>1.2.3.4</samp> and
- <samp>5.6.7.8</samp>) which resolve to the names
+ <p>The server has two IP addresses (<samp>172.20.30.40</samp> and
+ <samp>172.20.30.50</samp>) which resolve to the names
<samp>www.example1.com</samp> and <samp>www.example2.org</samp>
respectively.</p>
<pre>
Listen 80
- <VirtualHost 1.2.3.4>
+ <VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>
- <VirtualHost 5.6.7.8>
+ <VirtualHost 172.20.30.50>
DocumentRoot /www/example2
ServerName www.example2.org
</VirtualHost>
<p><strong>Setup:</strong></p>
- <p>The server machine has two IP addresses (<samp>1.2.3.4</samp> and
- <samp>5.6.7.8</samp>) which resolve to the names
+ <p>The server machine has two IP addresses (<samp>172.20.30.40</samp> and
+ <samp>172.20.30.50</samp>) which resolve to the names
<samp>www.example1.com</samp> and <samp>www.example2.org</samp>
respectively. In each case, we want to run hosts on ports 80 and
8080.</p>
<tr>
<td bgcolor="#eeeeee">
<pre>
- Listen 1.2.3.4:80
- Listen 1.2.3.4:8080
- Listen 5.6.7.8:80
- Listen 5.6.7.8:8080
+ Listen 172.20.30.40:80
+ Listen 172.20.30.40:8080
+ Listen 172.20.30.50:80
+ Listen 172.20.30.50:8080
- <VirtualHost 1.2.3.4:80>
+ <VirtualHost 172.20.30.40:80>
DocumentRoot /www/example1-80
ServerName www.example1.com
</VirtualHost>
- <VirtualHost 1.2.3.4:8080>
+ <VirtualHost 172.20.30.40:8080>
DocumentRoot /www/example1-8080
ServerName www.example1.com
</VirtualHost>
- <VirtualHost 5.6.7.8:80>
+ <VirtualHost 172.20.30.50:80>
DocumentRoot /www/example2-80
ServerName www.example1.org
</VirtualHost>
- <VirtualHost 5.6.7.8:8080>
+ <VirtualHost 172.20.30.50:8080>
DocumentRoot /www/example2-8080
ServerName www.example2.org
</VirtualHost>
<pre>
Listen 80
- NameVirtualHost 1.2.3.4
+ NameVirtualHost 172.20.30.40
- <VirtualHost 1.2.3.4>
+ <VirtualHost 172.20.30.40>
DocumentRoot /www/example1
ServerName www.example1.com
</VirtualHost>
- <VirtualHost 1.2.3.4>
+ <VirtualHost 172.20.30.40>
DocumentRoot /www/example2
ServerName www.example2.org
</VirtualHost>
- <VirtualHost 1.2.3.4>
+ <VirtualHost 172.20.30.40>
DocumentRoot /www/example3
ServerName www.example3.net
</VirtualHost>
# IP-based
- <VirtualHost 5.6.7.8>
+ <VirtualHost 172.20.30.50>
DocumentRoot /www/example4
ServerName www.example4.edu
</VirtualHost>
- <VirtualHost 9.8.7.6>
+ <VirtualHost 172.20.30.60>
DocumentRoot /www/example5
ServerName www.example5.gov
</VirtualHost>
<p><strong>Setup:</strong></p>
<p>The name-based vhost with the hostname
- <samp>www.otherdomain.tld</samp> (from our <a
+ <samp>www.example2.org</samp> (from our <a
href="#name">name-based</a> example, setup 2) should get its own IP
address. To avoid problems with name servers or proxies who cached the
old IP address for the name-based vhost we want to provide both
variants during a migration phase.<br />
The solution is easy, because we can simply add the new IP address
- (<samp>111.22.33.66</samp>) to the <code>VirtualHost</code>
+ (<samp>172.20.30.50</samp>) to the <code>VirtualHost</code>
directive.</p>
<p><strong>Server configuration:</strong></p>
<td bgcolor="#eeeeee">
<pre>
Listen 80
- ServerName www.domain.tld
- DocumentRoot /www/domain
+ ServerName www.example1.com
+ DocumentRoot /www/example1
- NameVirtualHost 111.22.33.55
+ NameVirtualHost 172.20.30.40
- <VirtualHost 111.22.33.55 111.22.33.66>
- DocumentRoot /www/otherdomain
- ServerName www.otherdomain.tld
+ <VirtualHost 172.20.30.40 172.20.30.50>
+ DocumentRoot /www/example2
+ ServerName www.example2.org
# ...
</VirtualHost>
- <VirtualHost 111.22.33.55>
- DocumentRoot /www/subdomain
- ServerName www.sub.domain.tld
- ServerAlias *.sub.domain.tld
+ <VirtualHost 172.20.30.40>
+ DocumentRoot /www/example3
+ ServerName www.example3.net
+ ServerAlias *.example3.net
# ...
</VirtualHost>
</pre>
<tr>
<td bgcolor="#eeeeee">
<pre>
- NameVirtualHost 111.22.33.44
+ NameVirtualHost 172.20.30.40
- <VirtualHost 111.22.33.44>
+ <VirtualHost 172.20.30.40>
# primary vhost
DocumentRoot /www/subdomain
RewriteEngine On
# ...
</VirtualHost>
- <VirtualHost 111.22.33.44>
+ <VirtualHost 172.20.30.40>
DocumentRoot /www/subdomain/sub1
ServerName www.sub1.domain.tld
ServerPath /sub1/
# ...
</VirtualHost>
- <VirtualHost 111.22.33.44>
+ <VirtualHost 172.20.30.40>
DocumentRoot /www/subdomain/sub2
ServerName www.sub2.domain.tld
ServerPath /sub2/