name-based.html.en revision 4aa603e6448b99f9371397d439795c91a93637ea
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding This file is generated from xml source: DO NOT EDIT
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<title>Name-based Virtual Host Support - Apache HTTP Server</title>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<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" />
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<script src="/style/scripts/prettify.min.js" type="text/javascript">
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<link href="/images/favicon.ico" rel="shortcut icon" /></head>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<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>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<p class="apache">Apache HTTP Server Version 2.5</p>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.5</a> > <a href="./">Virtual Hosts</a></div><div id="page-content"><div id="preamble"><h1>Name-based Virtual Host Support</h1>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<p><span>Available Languages: </span><a href="/de/vhosts/name-based.html" hreflang="de" rel="alternate" title="Deutsch"> de </a> |
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<a href="/en/vhosts/name-based.html" title="English"> en </a> |
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<a href="/fr/vhosts/name-based.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> |
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<a href="/ja/vhosts/name-based.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<a href="/ko/vhosts/name-based.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<a href="/tr/vhosts/name-based.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding <p>This document describes when and how to use name-based virtual hosts.</p>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<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>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<li><img alt="" src="/images/down.gif" /> <a href="#alg">How the server selects the proper name-based virtual host</a></li>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<li><img alt="" src="/images/down.gif" /> <a href="#using">Using Name-based Virtual Hosts</a></li>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding</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></ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding<h2><a name="namevip" id="namevip">Name-based vs. IP-based Virtual Hosts</a></h2>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding <p><a href="ip-based.html">IP-based virtual hosts</a> use the IP address of the connection to
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding determine the correct virtual host to serve. Therefore you need to
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding have a separate IP address for each host.</p>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding <p>With name-based virtual hosting, the server relies on the client to
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding report the hostname as part of the HTTP headers. Using this technique,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding many different hosts can share the same IP address.</p>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding <p>Name-based virtual hosting is usually simpler, since you need
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding only configure your DNS server to map each hostname to the correct
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding IP address and then configure the Apache HTTP Server to recognize
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding the different hostnames. Name-based virtual hosting also eases
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding the demand for scarce IP addresses. Therefore you should use
<code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> argument based on
compare the <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> and <code class="directive"><a href="/mod/core.html#serveralias">ServerAlias</a></code> directives to the server name
<h3><a name="defaultvhost" id="defaultvhost">The default name-based vhost for an IP and port combination </a></h3>
<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#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#virtualhost"><VirtualHost></a></code></li></ul></td></tr></table>
<p>The first step is to create a <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> block for
each different host that you would like to serve. Inside each <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> block, you will need at minimum a
<code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> directive to designate
which host is served and a <code class="directive"><a href="/mod/core.html#documentroot">DocumentRoot</a></code>
<p> Any request that doesn't match an existing <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> is handled by the global
with a <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> matching that of
<p> It is best to always explicitly list a <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> in every name-based virtual host.</p>
<p>If a <code class="directive"><a href="/mod/core.html#virtualhost">VirtualHost</a></code> doesn't specify
a <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code>, a server name will be
explicitly list a <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> in every
ServerName www.example.com
ServerAlias example.com
ServerName other.example.com
<code>*</code> in <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> directives. For example, you might want to do this
possible with the <code class="directive"><a href="/mod/core.html#serveralias">ServerAlias</a></code>
directive, placed inside the <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> section. For example in the first <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> block above, the
<code class="directive"><a href="/mod/core.html#serveralias">ServerAlias</a></code> directive indicates that
Of course, you can't just make up names and place them in <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> or <code>ServerAlias</code>. You must
<p>Name-based virtual hosts for the best-matching set of <code class="directive"><a href="/mod/core.html#virtualhost"><virtualhost></a></code>s are processed
in the order they appear in the configuration. The first matching <code class="directive"><a href="/mod/core.html#servername">ServerName</a></code> or <code class="directive"><a href="/mod/core.html#serveralias">ServerAlias</a></code> is used, with no different precedence for wildcards
<p>The complete list of names in the <code class="directive"><a href="/mod/core.html#virtualhost">VirtualHost</a></code>
by placing other directives inside the <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code> containers. Most directives can be
(outside any <code class="directive"><a href="/mod/core.html#virtualhost"><VirtualHost></a></code>
<p><span>Available Languages: </span><a href="/de/vhosts/name-based.html" hreflang="de" rel="alternate" title="Deutsch"> de </a> |
<a href="/fr/vhosts/name-based.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a> |
<a href="/ja/vhosts/name-based.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
<a href="/ko/vhosts/name-based.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
<a href="/tr/vhosts/name-based.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p>
</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&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>
var comments_identifier = 'http://httpd.apache.org/docs/trunk/vhosts/name-based.html';
if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
d.write('<div id="comments_thread"><\/div>');
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
(d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
<p class="apache">Copyright 2014 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>
<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[//><!--