github.com/krum110487/go-htaccess@v0.0.0-20240316004156-60641c8e7598/tests/data/apache_2_2_34/manual/vhosts/name-based.html.en (about) 1 <?xml version="1.0" encoding="ISO-8859-1"?> 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head> 4 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" /> 5 <!-- 6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 7 This file is generated from xml source: DO NOT EDIT 8 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 9 --> 10 <title>Name-based Virtual Host Support - Apache HTTP Server Version 2.2</title> 11 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> 12 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> 13 <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" /> 14 <script src="../style/scripts/prettify.min.js" type="text/javascript"> 15 </script> 16 17 <link href="../images/favicon.ico" rel="shortcut icon" /><link href="http://httpd.apache.org/docs/current/vhosts/name-based.html" rel="canonical" /></head> 18 <body id="manual-page"><div id="page-header"> 19 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.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> 20 <p class="apache">Apache HTTP Server Version 2.2</p> 21 <img alt="" src="../images/feather.gif" /></div> 22 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div> 23 <div id="path"> 24 <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.2</a> > <a href="./">Virtual Hosts</a></div><div id="page-content"><div class="retired"><h4>Please note</h4> 25 <p> This document refers to a legacy release (<strong>2.2</strong>) of Apache httpd. The active release (<strong>2.4</strong>) is documented <a href="http://httpd.apache.org/docs/current">here</a>. If you have not already upgraded, please follow <a href="http://httpd.apache.org/docs/current/upgrading.html">this link</a> for more information.</p> 26 <p>You may follow <a href="http://httpd.apache.org/docs/current/vhosts/name-based.html">this link</a> to go to the current version of this document.</p></div><div id="preamble"><h1>Name-based Virtual Host Support</h1> 27 <div class="toplang"> 28 <p><span>Available Languages: </span><a href="../de/vhosts/name-based.html" hreflang="de" rel="alternate" title="Deutsch"> de </a> | 29 <a href="../en/vhosts/name-based.html" title="English"> en </a> | 30 <a href="../fr/vhosts/name-based.html" hreflang="fr" rel="alternate" title="Français"> fr </a> | 31 <a href="../ja/vhosts/name-based.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 32 <a href="../ko/vhosts/name-based.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 33 <a href="../tr/vhosts/name-based.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p> 34 </div> 35 36 <p>This document describes when and how to use name-based virtual hosts.</p> 37 </div> 38 <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> 39 <li><img alt="" src="../images/down.gif" /> <a href="#using">Using Name-based Virtual Hosts</a></li> 40 <li><img alt="" src="../images/down.gif" /> <a href="#compat">Compatibility with Older Browsers</a></li> 41 </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><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 42 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> 43 <div class="section"> 44 <h2><a name="namevip" id="namevip">Name-based vs. IP-based Virtual Hosts</a></h2> 45 46 <p>IP-based virtual hosts use the IP address of the connection to 47 determine the correct virtual host to serve. Therefore you need to 48 have a separate IP address for each host. With name-based virtual 49 hosting, the server relies on the client to report the hostname as 50 part of the HTTP headers. Using this technique, many different hosts 51 can share the same IP address.</p> 52 53 <p>Name-based virtual hosting is usually simpler, since you need 54 only configure your DNS server to map each hostname to the correct 55 IP address and then configure the Apache HTTP Server to recognize 56 the different hostnames. Name-based virtual hosting also eases 57 the demand for scarce IP addresses. Therefore you should use 58 name-based virtual hosting unless you are using equipment 59 that explicitly demands IP-based hosting. Historical reasons for 60 IP-based virtual hosting based on client support are no longer 61 applicable to a general-purpose web server, unless you are 62 using a <code class="module"><a href="../mod/mod_ssl.html">mod_ssl</a></code> version without SNI support 63 (standard in Apache releases since 2.2.12).</p> 64 65 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> 66 <div class="section"> 67 <h2><a name="using" id="using">Using Name-based Virtual Hosts</a></h2> 68 69 <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> 70 71 <p>To use name-based virtual hosting, you must designate the IP 72 address (and possibly port) on the server that will be accepting 73 requests for the hosts. This is configured using the <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code> directive. 74 In the normal case where any and all IP addresses on the server should 75 be used, you can use <code>*</code> as the argument to <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code>. If you're planning to use 76 multiple ports (e.g. running SSL) you should add a Port to the argument, 77 such as <code>*:80</code>. Note that mentioning an IP address in a 78 <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code> directive does not 79 automatically make the server listen to that IP address. See 80 <a href="../bind.html">Setting which addresses and ports Apache uses</a> 81 for more details. In addition, any IP address specified here must be 82 associated with a network interface on the server.</p> 83 84 <p>The next step is to create a <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> block for 85 each different host that you would like to serve. The argument to the 86 <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> directive 87 must match a defined <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code> directive. (In this usual case, 88 this will be "*:80"). Inside each <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> block, you will need at minimum a 89 <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code> directive to designate 90 which host is served and a <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> 91 directive to show where in the filesystem the content for that host 92 lives.</p> 93 94 <div class="note"><h3>Main host goes away</h3> 95 <p>If you are adding virtual hosts to an existing web server, you 96 must also create a <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> block for the existing host. The <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code> and <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> included in this virtual host should be the 97 same as the global <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code> and 98 <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>. List this virtual 99 host first in the configuration file so that it will act as the default 100 host.</p> 101 </div> 102 103 <p>For example, suppose that you are serving the domain 104 <code>www.domain.tld</code> and you wish to add the virtual host 105 <code>www.otherdomain.tld</code>, which points at the same IP address. 106 Then you simply add the following to <code>httpd.conf</code>:</p> 107 108 <div class="example"><p><code> 109 NameVirtualHost *:80<br /> 110 <br /> 111 <VirtualHost *:80><br /> 112 <span class="indent"> 113 ServerName www.domain.tld<br /> 114 ServerAlias domain.tld *.domain.tld<br /> 115 DocumentRoot /www/domain<br /> 116 </span> 117 </VirtualHost><br /> 118 <br /> 119 <VirtualHost *:80><br /> 120 <span class="indent">ServerName www.otherdomain.tld<br /> 121 DocumentRoot /www/otherdomain<br /> 122 </span> 123 </VirtualHost><br /> 124 </code></p></div> 125 126 <p>You can alternatively specify an explicit IP address in place of the 127 <code>*</code> in both the <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code> and <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> directives. For example, you might want to do this 128 in order to run some name-based virtual hosts on one IP address, and either 129 IP-based, or another set of name-based virtual hosts on another address.</p> 130 131 <p>Many servers want to be accessible by more than one name. This is 132 possible with the <code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code> 133 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 134 <code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code> directive indicates that 135 the listed names are other names which people can use to see that same 136 web site:</p> 137 138 <div class="example"><p><code> 139 ServerAlias domain.tld *.domain.tld 140 </code></p></div> 141 142 <p>then requests for all hosts in the <code>domain.tld</code> domain will 143 be served by the <code>www.domain.tld</code> virtual host. The wildcard 144 characters <code>*</code> and <code>?</code> can be used to match names. 145 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 146 first have your DNS server properly configured to map those names to an IP 147 address associated with your server.</p> 148 149 <p>The complete list of names in the <code class="directive"><a href="../mod/core.html#virtualhost">VirtualHost</a></code> directive are treated just like a (non wildcard) 150 <code class="directive"><a href="../mod/core.html#serveralias">ServerAlias</a></code>.</p> 151 152 <p>Finally, you can fine-tune the configuration of the virtual hosts 153 by placing other directives inside the <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> containers. Most directives can be 154 placed in these containers and will then change the configuration only of 155 the relevant virtual host. To find out if a particular directive is allowed, 156 check the <a href="../mod/directive-dict.html#Context">Context</a> of the 157 directive. Configuration directives set in the <em>main server context</em> 158 (outside any <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> 159 container) will be used only if they are not overridden by the virtual host 160 settings.</p> 161 162 <p>Now when a request arrives, the server will first check if it is using 163 an IP address that matches the <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code>. If it is, then it will look at each <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> section with a matching 164 IP address and try to find one where the <code class="directive"><a href="../mod/core.html#servername">ServerName</a></code> or <code>ServerAlias</code> matches the requested 165 hostname. If it finds one, then it uses the configuration for that server. 166 If no matching virtual host is found, then <strong>the first listed virtual 167 host</strong> that matches the IP address will be used.</p> 168 169 <p>As a consequence, the first listed virtual host is the <em>default</em> 170 virtual host. The <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> from 171 the <em>main server</em> will <strong>never</strong> be used when an IP 172 address matches the <code class="directive"><a href="../mod/core.html#namevirtualhost">NameVirtualHost</a></code> 173 directive. If you would like to have a special configuration for requests 174 that do not match any particular virtual host, simply put that configuration 175 in a <code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> 176 container and list it first in the configuration file.</p> 177 178 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> 179 <div class="section"> 180 <h2><a name="compat" id="compat">Compatibility with Older Browsers</a></h2> 181 182 <p>As mentioned earlier, there are some clients 183 who do not send the required data for the name-based virtual 184 hosts to work properly. These clients will always be sent the 185 pages from the first virtual host listed for that IP address 186 (the <cite>primary</cite> name-based virtual host).</p> 187 188 <div class="note"><h3>How much older?</h3> 189 <p>Please note that when we say older, we really do mean older. You are 190 very unlikely to encounter one of these browsers in use today. All 191 current versions of any browser send the <code>Host</code> header as 192 required for name-based virtual hosts.</p> 193 </div> 194 195 <p>There is a possible workaround with the <code class="directive"><a href="../mod/core.html#serverpath">ServerPath</a></code> 196 directive, albeit a slightly cumbersome one:</p> 197 198 <p>Example configuration:</p> 199 200 <div class="example"><p><code> 201 NameVirtualHost 111.22.33.44<br /> 202 <br /> 203 <VirtualHost 111.22.33.44><br /> 204 <span class="indent"> 205 ServerName www.domain.tld<br /> 206 ServerPath /domain<br /> 207 DocumentRoot /web/domain<br /> 208 </span> 209 </VirtualHost><br /> 210 </code></p></div> 211 212 <p>What does this mean? It means that a request for any URI 213 beginning with "<code>/domain</code>" will be served from the 214 virtual host <code>www.domain.tld</code>. This means that the 215 pages can be accessed as <code>http://www.domain.tld/domain/</code> 216 for all clients, although clients sending a <code>Host:</code> header 217 can also access it as <code>http://www.domain.tld/</code>.</p> 218 219 <p>In order to make this work, put a link on your primary 220 virtual host's page to 221 <code>http://www.domain.tld/domain/</code>. Then, in the virtual 222 host's pages, be sure to use either purely relative links 223 (<em>e.g.</em>, "<code>file.html</code>" or 224 "<code>../icons/image.gif</code>") or links containing the 225 prefacing <code>/domain/</code> (<em>e.g.</em>, 226 "<code>http://www.domain.tld/domain/misc/file.html</code>" or 227 "<code>/domain/misc/file.html</code>").</p> 228 229 <p>This requires a bit of discipline, but adherence to these 230 guidelines will, for the most part, ensure that your pages will 231 work with all browsers, new and old.</p> 232 233 </div></div> 234 <div class="bottomlang"> 235 <p><span>Available Languages: </span><a href="../de/vhosts/name-based.html" hreflang="de" rel="alternate" title="Deutsch"> de </a> | 236 <a href="../en/vhosts/name-based.html" title="English"> en </a> | 237 <a href="../fr/vhosts/name-based.html" hreflang="fr" rel="alternate" title="Français"> fr </a> | 238 <a href="../ja/vhosts/name-based.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 239 <a href="../ko/vhosts/name-based.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 240 <a href="../tr/vhosts/name-based.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p> 241 </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> 242 <script type="text/javascript"><!--//--><![CDATA[//><!-- 243 var comments_shortname = 'httpd'; 244 var comments_identifier = 'http://httpd.apache.org/docs/2.2/vhosts/name-based.html'; 245 (function(w, d) { 246 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 247 d.write('<div id="comments_thread"><\/div>'); 248 var s = d.createElement('script'); 249 s.type = 'text/javascript'; 250 s.async = true; 251 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 252 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 253 } 254 else { 255 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 256 } 257 })(window, document); 258 //--><!]]></script></div><div id="footer"> 259 <p class="apache">Copyright 2017 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> 260 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.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[//><!-- 261 if (typeof(prettyPrint) !== 'undefined') { 262 prettyPrint(); 263 } 264 //--><!]]></script> 265 </body></html>