examples.html.en revision 2fae9d127f7143fabe8f73958eb9bde31df17d41
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<?xml version="1.0" encoding="ISO-8859-1"?>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess This file is generated from xml source: DO NOT EDIT
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5a58787efeb02a1c3f06569d019ad81fd2efa06end -->
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc<title>VirtualHost Examples - Apache HTTP Server Version 2.5</title>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
5a58787efeb02a1c3f06569d019ad81fd2efa06end<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" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" />
2e545ce2450a9953665f701bb05350f0d3f26275nd<script src="/style/scripts/prettify.min.js" type="text/javascript">
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen</script>
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen
5a58787efeb02a1c3f06569d019ad81fd2efa06end<link href="/images/favicon.ico" rel="shortcut icon" /></head>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<body id="manual-page"><div id="page-header">
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd<p class="apache">Apache HTTP Server Version 2.5</p>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<img alt="" src="/images/feather.gif" /></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<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/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Virtual Hosts</a></div><div id="page-content"><div id="preamble"><h1>VirtualHost Examples</h1>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<div class="toplang">
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/vhosts/examples.html" title="English">&nbsp;en&nbsp;</a> |
d05d0eb4ae6d2a5e513fc3bf2555ce33da416634nd<a href="/fr/vhosts/examples.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd<a href="/ja/vhosts/examples.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
4b3a8afbfcea8b265d179a122bf40dfedd1ce280takashi<a href="/ko/vhosts/examples.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<a href="/tr/vhosts/examples.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd</div>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>This document attempts to answer the commonly-asked questions about
c573a8f047f4fbd3611d06ed1613e6f4679ef599rbowen setting up <a href="index.html">virtual hosts</a>. These scenarios are those involving multiple
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen 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.
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen </p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5a58787efeb02a1c3f06569d019ad81fd2efa06end</div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#purename">Running several name-based web
5a58787efeb02a1c3f06569d019ad81fd2efa06end sites on a single IP address.</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#twoips">Name-based hosts on more than one
5a58787efeb02a1c3f06569d019ad81fd2efa06end IP address.</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#intraextra">Serving the same content on
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess different IP addresses (such as an internal and external
5a58787efeb02a1c3f06569d019ad81fd2efa06end address).</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#port">Running different sites on different
5a58787efeb02a1c3f06569d019ad81fd2efa06end ports.</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#ip">IP-based virtual hosting</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#ipport">Mixed port-based and ip-based virtual
5ae30adbe59946de742ab0cd6be3b7457471a698takashi hosts</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#mixed">Mixed name-based and IP-based
5a58787efeb02a1c3f06569d019ad81fd2efa06end vhosts</a></li>
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen<li><img alt="" src="/images/down.gif" /> <a href="#proxy">Using <code>Virtual_host</code> and
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen mod_proxy together</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#default">Using <code>_default_</code>
5a58787efeb02a1c3f06569d019ad81fd2efa06end vhosts</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#migrate">Migrating a name-based vhost to an
5a58787efeb02a1c3f06569d019ad81fd2efa06end IP-based vhost</a></li>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<li><img alt="" src="/images/down.gif" /> <a href="#serverpath">Using the <code>ServerPath</code>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi directive</a></li>
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="purename" id="purename">Running several name-based web
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess sites on a single IP address.</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung <p>Your server has multiple hostnames that resolve to a single address,
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung and you want to respond differently for <code>www.example.com</code>
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung and <code>www.example.org</code>.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <div class="note"><h3>Note</h3><p>Creating virtual
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess host configurations on your Apache server does not magically
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess cause DNS entries to be created for those host names. You
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <em>must</em> have the names in DNS, resolving to your IP
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess address, or nobody else will be able to see your web site. You
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess can put entries in your <code>hosts</code> file for local
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess testing, but that will work only from the machine with those
3c29010ad1a706e8d5931b250f1bc751e0dde676rbowen <code>hosts</code> entries.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </div>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config"># Ensure that Apache listens on port 80
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowenListen 80
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost *:80&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example1"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.com
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # Other directives here
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost *:80&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example2"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.org
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # Other directives here
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The asterisks match all addresses, so the main server serves no
6f7c18e70781deff3d1129774221de81b43c828end requests. Due to the fact that the virtual host with
6f7c18e70781deff3d1129774221de81b43c828end <code>ServerName www.example.com</code> is first
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess in the configuration file, it has the highest priority and can be seen
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess as the <cite>default</cite> or <cite>primary</cite> server. That means
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess that if a request is received that does not match one of the specified
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>ServerName</code> directives, it will be served by this first
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>VirtualHost</code>.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung <p>The above configuration is what you will want to use in almost
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung all name-based virtual hosting situations. The only thing that this
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung configuration will not work for, in fact, is when you are serving
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung different content based on differing IP addresses or ports.</p>
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <div class="note">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <h3>Note</h3>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung <p>You may replace <code>*</code> with a specific IP address
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung on the system. Such virtual hosts will only be used for
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung HTTP requests received on connection to the specified IP
2eb7a8afc318286c210a1fbb2ff2ba904471956frjung address.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>However, it is additionally useful to use <code>*</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess on systems where the IP address is not predictable - for
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess example if you have a dynamic IP address with your ISP, and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess you are using some variety of dynamic DNS solution. Since
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>*</code> matches any IP address, this configuration
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess would work without changes whenever your IP address
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess changes.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </div>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="twoips" id="twoips">Name-based hosts on more than one
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess IP address.</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <div class="note">
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <h3>Note</h3>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <p>Any of the techniques discussed here can be extended to any
5ae30adbe59946de742ab0cd6be3b7457471a698takashi number of IP addresses.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </div>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The server has two IP addresses. On one (<code>172.20.30.40</code>), we
d565edaec710102f7e7d06252aaf1de67b7ddd25rbowen will serve the "main" server, <code>server.example.com</code> and on the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess other (<code>172.20.30.50</code>), we will serve two or more virtual hosts.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">Listen 80
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen# This is the "main" server running on 172.20.30.40
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowenServerName server.example.com
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coarDocumentRoot "/www/mainserver"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.50&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example1"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.com
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # Other directives here ...
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.50&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example2"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.org
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # Other directives here ...
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Any request to an address other than <code>172.20.30.50</code> will be
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess served from the main server. A request to <code>172.20.30.50</code> with an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess unknown hostname, or no <code>Host:</code> header, will be served from
261c62b53a9c707c64c7824eed68b5463bd23e62nd <code>www.example.com</code>.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="intraextra" id="intraextra">Serving the same content on
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess different IP addresses (such as an internal and external
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess address).</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The server machine has two IP addresses (<code>192.168.1.1</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess and <code>172.20.30.40</code>). The machine is sitting between an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess internal (intranet) network and an external (internet) network. Outside
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess of the network, the name <code>server.example.com</code> resolves to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess the external address (<code>172.20.30.40</code>), but inside the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess network, that same name resolves to the internal address
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess (<code>192.168.1.1</code>).</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The server can be made to respond to internal and external requests
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess with the same content, with just one <code>VirtualHost</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess section.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">&lt;VirtualHost 192.168.1.1 172.20.30.40&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/server1"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName server.example.com
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerAlias server
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Now requests from both networks will be served from the same
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>VirtualHost</code>.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <div class="note">
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <h3>Note:</h3><p>On the internal
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess network, one can just use the name <code>server</code> rather
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess than the fully qualified host name
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>server.example.com</code>.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Note also that, in the above example, you can replace the list
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess of IP addresses with <code>*</code>, which will cause the server to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess respond the same on all addresses.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess </div>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="port" id="port">Running different sites on different
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess ports.</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>You have multiple domains going to the same IP and also want to
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf serve multiple ports. The example below illustrates that the name-matching
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf takes place after the best matching IP address and port combination
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf is determined.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">Listen 80
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowenListen 8080
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40:80&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.com
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/domain-80"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40:8080&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.com
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/domain-8080"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40:80&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.org
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/otherdomain-80"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40:8080&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.org
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/otherdomain-8080"
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="ip" id="ip">IP-based virtual hosting</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The server has two IP addresses (<code>172.20.30.40</code> and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>172.20.30.50</code>) which resolve to the names
261c62b53a9c707c64c7824eed68b5463bd23e62nd <code>www.example.com</code> and <code>www.example.org</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess respectively.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">Listen 80
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example1"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.com
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.50&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example2"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.org
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Requests for any address not specified in one of the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>&lt;VirtualHost&gt;</code> directives (such as
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>localhost</code>, for example) will go to the main server, if
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess there is one.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="ipport" id="ipport">Mixed port-based and ip-based virtual
5ae30adbe59946de742ab0cd6be3b7457471a698takashi hosts</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The server machine has two IP addresses (<code>172.20.30.40</code> and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>172.20.30.50</code>) which resolve to the names
261c62b53a9c707c64c7824eed68b5463bd23e62nd <code>www.example.com</code> and <code>www.example.org</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess respectively. In each case, we want to run hosts on ports 80 and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess 8080.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">Listen 172.20.30.40:80
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowenListen 172.20.30.40:8080
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowenListen 172.20.30.50:80
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowenListen 172.20.30.50:8080
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40:80&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example1-80"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.com
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40:8080&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example1-8080"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.com
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.50:80&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example2-80"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.org
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.50:8080&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example2-8080"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.org
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="mixed" id="mixed">Mixed name-based and IP-based
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess vhosts</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf <p>Any address mentioned in the argument to a virtualhost that never
6e14faf37935e36804b8bad802bc9dd58f3cf65dsf appears in another virtual host is a strictly IP-based virtual host.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">Listen 80
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example1"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.com
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example2"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.org
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example3"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.net
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen# IP-based
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.50&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example4"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.edu
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.60&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example5"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.gov
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen<h2><a name="proxy" id="proxy">Using <code>Virtual_host</code> and
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen mod_proxy together</a></h2>
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen <p>The following example allows a front-end machine to proxy a
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen virtual host through to a server running on another machine. In the
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen example, a virtual host of the same name is configured on a machine
b244bbf442a0aea3dc397b4d0d751f4716c5891dnd at <code>192.168.111.2</code>. The <code class="directive"><a href="/mod/mod_proxy.html#proxypreservehost">ProxyPreserveHost
b244bbf442a0aea3dc397b4d0d751f4716c5891dnd On</a></code> directive is used so that the desired hostname is
b244bbf442a0aea3dc397b4d0d751f4716c5891dnd passed through, in case we are proxying multiple hostnames to a
b244bbf442a0aea3dc397b4d0d751f4716c5891dnd single machine.</p>
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">&lt;VirtualHost *:*&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ProxyPreserveHost On
2fae9d127f7143fabe8f73958eb9bde31df17d41coar ProxyPass "/" "http://192.168.111.2/"
2fae9d127f7143fabe8f73958eb9bde31df17d41coar ProxyPassReverse "/" "http://192.168.111.2/"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName hostname.example.com
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
f8dee27891059abb09ff5ca3fc5434f5719d22a0rbowen<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="default" id="default">Using <code>_default_</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess vhosts</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi <h3><a name="defaultallports" id="defaultallports"><code>_default_</code> vhosts
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess for all ports</a></h3>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Catching <em>every</em> request to any unspecified IP address and
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess port, <em>i.e.</em>, an address/port combination that is not used for
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess any other virtual host.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">&lt;VirtualHost _default_:*&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/default"
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Using such a default vhost with a wildcard port effectively prevents
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess any request going to the main server.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>A default vhost never serves a request that was sent to an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess address/port that is used for name-based vhosts. If the request
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess contained an unknown or no <code>Host:</code> header it is always
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess served from the primary name-based vhost (the vhost for that
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess address/port appearing first in the configuration file).</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>You can use <code class="directive"><a href="/mod/mod_alias.html#aliasmatch">AliasMatch</a></code> or
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> to rewrite any
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess request to a single information page (or script).</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <h3><a name="defaultdifferentports" id="defaultdifferentports"><code>_default_</code> vhosts
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess for different ports</a></h3>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Same as setup 1, but the server listens on several ports and we want
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to use a second <code>_default_</code> vhost for port 80.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">&lt;VirtualHost _default_:80&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/default80"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # ...
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost _default_:*&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/default"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # ...
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The default vhost for port 80 (which <em>must</em> appear before any
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess default vhost with a wildcard port) catches all requests that were sent
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess to an unspecified IP address. The main server is never used to serve a
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess request.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <h3><a name="defaultoneport" id="defaultoneport"><code>_default_</code> vhosts
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess for one port</a></h3>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>We want to have a default vhost for port 80, but no other default
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess vhosts.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">&lt;VirtualHost _default_:80&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/default"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen...
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>A request to an unspecified address on port 80 is served from the
d5b8072762cf428c4c703ed7054ae948d41c910bnd default vhost. Any other request to an unspecified address and port is
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess served from the main server.</p>
3c29010ad1a706e8d5931b250f1bc751e0dde676rbowen
3c29010ad1a706e8d5931b250f1bc751e0dde676rbowen <p>Any use of <code>*</code> in a virtual host declaration will have
3c29010ad1a706e8d5931b250f1bc751e0dde676rbowen higher precedence than <code>_default_</code>.</p>
3c29010ad1a706e8d5931b250f1bc751e0dde676rbowen
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="migrate" id="migrate">Migrating a name-based vhost to an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess IP-based vhost</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The name-based vhost with the hostname
261c62b53a9c707c64c7824eed68b5463bd23e62nd <code>www.example.org</code> (from our <a href="#name">name-based</a> example, setup 2) should get its own IP
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess address. To avoid problems with name servers or proxies who cached the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess old IP address for the name-based vhost we want to provide both
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd variants during a migration phase.</p>
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd <p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess The solution is easy, because we can simply add the new IP address
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess (<code>172.20.30.50</code>) to the <code>VirtualHost</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directive.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">Listen 80
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowenServerName www.example.com
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coarDocumentRoot "/www/example1"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40 172.20.30.50&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example2"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.org
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # ...
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/example3"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.example.net
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerAlias *.example.net
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # ...
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>The vhost can now be accessed through the new address (as an
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess IP-based vhost) and through the old address (as a name-based
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess vhost).</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
5a58787efeb02a1c3f06569d019ad81fd2efa06end<div class="section">
5a58787efeb02a1c3f06569d019ad81fd2efa06end<h2><a name="serverpath" id="serverpath">Using the <code>ServerPath</code>
5ae30adbe59946de742ab0cd6be3b7457471a698takashi directive</a></h2>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>We have a server with two name-based vhosts. In order to match the
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess correct virtual host a client must send the correct <code>Host:</code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess header. Old HTTP/1.0 clients do not send such a header and Apache has
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess no clue what vhost the client tried to reach (and serves the request
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess from the primary vhost). To provide as much backward compatibility as
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess possible we create a primary vhost which returns a single page
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess containing links with an URL prefix to the name-based virtual
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess hosts.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
4aa603e6448b99f9371397d439795c91a93637eand <pre class="prettyprint lang-config">&lt;VirtualHost 172.20.30.40&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # primary vhost
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/subdomain"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen RewriteEngine On
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen RewriteRule . /www/subdomain/index.html
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # ...
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/subdomain/sub1"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.sub1.domain.tld
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerPath /sub1/
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen RewriteEngine On
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen RewriteRule ^(/sub1/.*) /www/subdomain$1
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # ...
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;/VirtualHost&gt;
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen&lt;VirtualHost 172.20.30.40&gt;
c3c937a1510d6ff9cfa28ef3713e787f0e1a39c9coar DocumentRoot "/www/subdomain/sub2"
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerName www.sub2.domain.tld
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen ServerPath /sub2/
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen RewriteEngine On
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen RewriteRule ^(/sub2/.*) /www/subdomain$1
c3c006c28c5b03892ccaef6e4d2cbb15a13a2072rbowen # ...
4aa603e6448b99f9371397d439795c91a93637eand&lt;/VirtualHost&gt;</pre>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <p>Due to the <code class="directive"><a href="/mod/core.html#serverpath">ServerPath</a></code>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess directive a request to the URL
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>http://www.sub1.domain.tld/sub1/</code> is <em>always</em> served
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess from the sub1-vhost.<br /> A request to the URL
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>http://www.sub1.domain.tld/</code> is only
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess served from the sub1-vhost if the client sent a correct
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>Host:</code> header. If no <code>Host:</code> header is sent the
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd client gets the information page from the primary host.</p>
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd <p>Please note that there is one oddity: A request to
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>http://www.sub2.domain.tld/sub1/</code> is also served from the
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd sub1-vhost if the client sent no <code>Host:</code> header.</p>
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd
a795ca2487c774aa6fe75c765a2bf17f969f7af7nd <p>The <code class="directive"><a href="/mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> directives
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess are used to make sure that a client which sent a correct
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess <code>Host:</code> header can use both URL variants, <em>i.e.</em>,
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess with or without URL prefix.</p>
fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2kess
5ae30adbe59946de742ab0cd6be3b7457471a698takashi </div></div>
3b3b7fc78d1f5bfc2769903375050048ff41ff26nd<div class="bottomlang">
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd<p><span>Available Languages: </span><a href="/en/vhosts/examples.html" title="English">&nbsp;en&nbsp;</a> |
d05d0eb4ae6d2a5e513fc3bf2555ce33da416634nd<a href="/fr/vhosts/examples.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a> |
7f5b59ccc63c0c0e3e678a168f09ee6a2f51f9d0nd<a href="/ja/vhosts/examples.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
4b3a8afbfcea8b265d179a122bf40dfedd1ce280takashi<a href="/ko/vhosts/examples.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung<a href="/tr/vhosts/examples.html" hreflang="tr" rel="alternate" title="T�rk�e">&nbsp;tr&nbsp;</a></p>
727872d18412fc021f03969b8641810d8896820bhumbedooh</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
0d0ba3a410038e179b695446bb149cce6264e0abnd<script type="text/javascript"><!--//--><![CDATA[//><!--
727872d18412fc021f03969b8641810d8896820bhumbedoohvar comments_shortname = 'httpd';
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedoohvar comments_identifier = 'http://httpd.apache.org/docs/trunk/vhosts/examples.html';
0d0ba3a410038e179b695446bb149cce6264e0abnd(function(w, d) {
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
727872d18412fc021f03969b8641810d8896820bhumbedooh d.write('<div id="comments_thread"><\/div>');
0d0ba3a410038e179b695446bb149cce6264e0abnd var s = d.createElement('script');
0d0ba3a410038e179b695446bb149cce6264e0abnd s.type = 'text/javascript';
0d0ba3a410038e179b695446bb149cce6264e0abnd s.async = true;
ac082aefa89416cbdc9a1836eaf3bed9698201c8humbedooh s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
0d0ba3a410038e179b695446bb149cce6264e0abnd (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
0d0ba3a410038e179b695446bb149cce6264e0abnd }
0d0ba3a410038e179b695446bb149cce6264e0abnd else {
727872d18412fc021f03969b8641810d8896820bhumbedooh d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
0d0ba3a410038e179b695446bb149cce6264e0abnd }
0d0ba3a410038e179b695446bb149cce6264e0abnd})(window, document);
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh//--><!]]></script></div><div id="footer">
205f749042ed530040a4f0080dbcb47ceae8a374rjung<p class="apache">Copyright 2015 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>
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
0d0ba3a410038e179b695446bb149cce6264e0abndif (typeof(prettyPrint) !== 'undefined') {
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd prettyPrint();
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd}
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd//--><!]]></script>
5a58787efeb02a1c3f06569d019ad81fd2efa06end</body></html>