name-based.html.en revision fefb8b844b6286bfc41bb2e0c4cc003b8e7d4ff2
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
3726777f47ac4bba3e21b075905959bbea47e72eerikabele XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3726777f47ac4bba3e21b075905959bbea47e72eerikabele This file is generated from xml source: DO NOT EDIT
3726777f47ac4bba3e21b075905959bbea47e72eerikabele XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3726777f47ac4bba3e21b075905959bbea47e72eerikabele --><title>Name-based Virtual Host Support - Apache HTTP Server</title><link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /><link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /><link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link href="/images/favicon.ico" rel="shortcut icon" /></head><body id="manual-page"><div id="page-header"><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><p class="apache">Apache HTTP Server Version 2.0</p><img alt="" src="/images/feather.gif" /></div><div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div><div id="path"><a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs-project/">Documentation</a> > <a href="../">Version 2.0</a></div><div id="page-content"><div id="preamble"><h1>Name-based Virtual Host Support</h1>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <p>This document describes when and how to use name-based virtual hosts.</p>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele</div><div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#namevip">Name-based vs. IP-based Virtual Hosts</a></li><li><img alt="" src="/images/down.gif" /> <a href="#using">Using Name-based Virtual Hosts</a></li><li><img alt="" src="/images/down.gif" /> <a href="#">Compatibility with Older Browsers</a></li></ul><h3>See also</h3><ul class="seealso"><li><a href="ip-based.html">IP-based Virtual Host Support</a></li><li><a href="details.html">An In-Depth Discussion of Virtual Host Matching</a></li><li><a href="mass.html">Dynamically configured mass virtual hosting</a></li><li><a href="examples.html">Virtual Host examples for common setups</a></li><li><a href="examples.html#serverpath">ServerPath configuration example</a></li></ul></div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="namevip" id="namevip">Name-based vs. IP-based Virtual Hosts</a></h2>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <p>IP-based virtual hosts use the IP address of the connection to
3726777f47ac4bba3e21b075905959bbea47e72eerikabele determine the correct virtual host to serve. Therefore you need to
3726777f47ac4bba3e21b075905959bbea47e72eerikabele have a separate IP address for each host. With name-based virtual
3726777f47ac4bba3e21b075905959bbea47e72eerikabele hosting, the server relies on the client to report the hostname as
3726777f47ac4bba3e21b075905959bbea47e72eerikabele part of the HTTP headers. Using this technique, many different hosts
3726777f47ac4bba3e21b075905959bbea47e72eerikabele can share the same IP address.</p>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <p>Name-based virtual hosting is usually simpler, since you need
3726777f47ac4bba3e21b075905959bbea47e72eerikabele only configure your DNS server to map each hostname to the correct
3726777f47ac4bba3e21b075905959bbea47e72eerikabele IP address and then configure the Apache HTTP Server to recognize
3726777f47ac4bba3e21b075905959bbea47e72eerikabele the different hostnames. Name-based virtual hosting also eases
3726777f47ac4bba3e21b075905959bbea47e72eerikabele the demand for scarce IP addresses. Therefore you should use
3726777f47ac4bba3e21b075905959bbea47e72eerikabele name-based virtual hosting unless there is a specific reason to
3726777f47ac4bba3e21b075905959bbea47e72eerikabele choose IP-based virtual hosting. Some reasons why you might consider
3726777f47ac4bba3e21b075905959bbea47e72eerikabele using IP-based virtual hosting:</p>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <li>Some ancient clients are not compatible with name-based virtual
3726777f47ac4bba3e21b075905959bbea47e72eerikabele hosting. For name-based virtual hosting to work, the client must send
3726777f47ac4bba3e21b075905959bbea47e72eerikabele the HTTP Host header. This is required by HTTP/1.1, and is
3726777f47ac4bba3e21b075905959bbea47e72eerikabele implemented by all modern HTTP/1.0 browsers as an extension. If you
3726777f47ac4bba3e21b075905959bbea47e72eerikabele need to support obsolete clients and still use name-based virtual
3726777f47ac4bba3e21b075905959bbea47e72eerikabele hosting, a possible technique is discussed at the end of this
3726777f47ac4bba3e21b075905959bbea47e72eerikabele document.</li>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <li>Name-based virtual hosting cannot be used with SSL secure servers
3726777f47ac4bba3e21b075905959bbea47e72eerikabele because of the nature of the SSL protocol.</li>
d03dd7e22aeb4b6940fb43d02db1233c1bedd799nd <li>Some operating systems and network equipment implement bandwidth
d03dd7e22aeb4b6940fb43d02db1233c1bedd799nd management techniques that cannot differentiate between hosts unless
3726777f47ac4bba3e21b075905959bbea47e72eerikabele they are on separate IP addresses.</li>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="using" id="using">Using Name-based Virtual Hosts</a></h2>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele<table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="/mod/core.html">core</a></code></li></ul></td><td><ul><li><code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code></li><li><code class="directive"><a href="/mod/core.html#namevirtualhost">NameVirtualHost</a></code></li><li><code class="directive"><a href="/mod/core.html#serveralias">ServerAlias</a></code></li><li><code class="directive"><a href="/mod/core.html#servername">ServerName</a></code></li><li><code class="directive"><a href="/mod/core.html#serverpath">ServerPath</a></code></li><li><code class="directive"><a href="/mod/core.html#virtualhost">VirtualHost</a></code></li></ul></td></tr></table>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <p>To use name-based virtual hosting, you must designate the IP
3726777f47ac4bba3e21b075905959bbea47e72eerikabele address (and possibly port) on the server that will be accepting
3726777f47ac4bba3e21b075905959bbea47e72eerikabele requests for the hosts. This is configured using the <code class="directive"><a href="/mod/core.html#namevirtualhost">NameVirtualHost</a></code> directive.
3726777f47ac4bba3e21b075905959bbea47e72eerikabele In the normal case where any and all IP addresses on the server should
3726777f47ac4bba3e21b075905959bbea47e72eerikabele be used, you can use <code>*</code> as the argument to
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <code>NameVirtualHost</code>. Note that mentioning an IP address in a
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <code>NameVirtualHost</code> directive does not automatically make the
3726777f47ac4bba3e21b075905959bbea47e72eerikabele server listen to that IP address. See <a href="/bind.html">Setting
3726777f47ac4bba3e21b075905959bbea47e72eerikabele which addresses and ports Apache uses</a> for more details. In addition,
3726777f47ac4bba3e21b075905959bbea47e72eerikabele any IP address specified here must be associated with a network interface
3726777f47ac4bba3e21b075905959bbea47e72eerikabele on the server.</p>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <p>The next step is to create a <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> block for
3726777f47ac4bba3e21b075905959bbea47e72eerikabele each different host that you would like to serve. The argument to the
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <code><VirtualHost></code> directive should be the same as the
3726777f47ac4bba3e21b075905959bbea47e72eerikabele argument to the <code>NameVirtualHost</code> directive (ie, an IP
3726777f47ac4bba3e21b075905959bbea47e72eerikabele address, or <code>*</code> for all addresses). Inside each
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <code><VirtualHost></code> block, you will need at minimum a /
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> directive to
3726777f47ac4bba3e21b075905959bbea47e72eerikabele designate which host is served and a <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code> directive to
3726777f47ac4bba3e21b075905959bbea47e72eerikabele show where in the filesystem the content for that host lives.</p>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <p>If you are adding virtual hosts to an existing web server, you
d03dd7e22aeb4b6940fb43d02db1233c1bedd799nd must also create a <VirtualHost> block for the existing host.
d03dd7e22aeb4b6940fb43d02db1233c1bedd799nd The <code>ServerName</code> and <code>DocumentRoot</code> included in
3726777f47ac4bba3e21b075905959bbea47e72eerikabele this virtual host should be the same as the global
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <code>ServerName</code> and <code>DocumentRoot</code>. List this
3726777f47ac4bba3e21b075905959bbea47e72eerikabele virtual host first in the configuration file so that it will act as
3726777f47ac4bba3e21b075905959bbea47e72eerikabele the default host.</p>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <p>For example, suppose that you are serving the domain
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <code>www.domain.tld</code> and you wish to add the virtual host
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <code>www.otherdomain.tld</code>, which points at the same IP address.
3726777f47ac4bba3e21b075905959bbea47e72eerikabele Then you simply add the following to <code>httpd.conf</code>:</p>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele NameVirtualHost *
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <VirtualHost *>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele </VirtualHost>
d03dd7e22aeb4b6940fb43d02db1233c1bedd799nd <VirtualHost *>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele </VirtualHost>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <p>You can alternatively specify an explicit IP address in place of
3726777f47ac4bba3e21b075905959bbea47e72eerikabele the * in both the <code>NameVirtualHost</code> and
3726777f47ac4bba3e21b075905959bbea47e72eerikabele <p>Many servers want to be accessible by more than one name. This is
3726777f47ac4bba3e21b075905959bbea47e72eerikabele possible with the <code class="directive"><a href="/mod/core.html#serveralias">ServerAlias</a></code>
3726777f47ac4bba3e21b075905959bbea47e72eerikabele directive, placed inside the <VirtualHost> section. For
3726777f47ac4bba3e21b075905959bbea47e72eerikabele example if you add this to the first <VirtualHost> block
</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div><div class="section"><h2><a name="" id="">Compatibility with Older Browsers</a></h2>
<p>There is a possible workaround with the <code class="directive"><a href="/mod/core.html#serverpath">ServerPath</a></code>
</div></div><div id="footer"><p class="apache">Maintained by the <a href="http://httpd.apache.org/docs-project/">Apache HTTP Server Documentation Project</a></p><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></body></html>