]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_vhost_alias.html.en
Rebuild.
[apache] / docs / manual / mod / mod_vhost_alias.html.en
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>mod_vhost_alias - Apache HTTP Server Version 2.5</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" /></head>
18 <body>
19 <div id="page-header">
20 <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>
21 <p class="apache">Apache HTTP Server Version 2.5</p>
22 <img alt="" src="../images/feather.png" /></div>
23 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
24 <div id="path">
25 <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="./">Modules</a></div>
26 <div id="page-content">
27 <div id="preamble"><h1>Apache Module mod_vhost_alias</h1>
28 <div class="toplang">
29 <p><span>Available Languages: </span><a href="../en/mod/mod_vhost_alias.html" title="English">&nbsp;en&nbsp;</a> |
30 <a href="../tr/mod/mod_vhost_alias.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
31 </div>
32 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides for dynamically configured mass virtual
33 hosting</td></tr>
34 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr>
35 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>vhost_alias_module</td></tr>
36 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_vhost_alias.c</td></tr></table>
37 <h3>Summary</h3>
38
39     <p>This module creates dynamically configured virtual hosts, by
40     allowing the IP address and/or the <code>Host:</code> header of
41     the HTTP request to be used as part of the pathname to
42     determine what files to serve. This allows for easy use of a
43     huge number of virtual hosts with similar configurations.</p>
44
45     <div class="note"><h3>Note</h3>
46       <p>If <code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code> or <code class="module"><a href="../mod/mod_userdir.html">mod_userdir</a></code> are
47       used for translating URIs to filenames, they will override the
48       directives of <code class="module"><a href="../mod/mod_vhost_alias.html">mod_vhost_alias</a></code> described below. For
49       example, the following configuration will map <code>
50       /cgi-bin/script.pl</code> to <code>
51       /usr/local/apache2/cgi-bin/script.pl</code> in all cases:</p>
52
53       <pre class="prettyprint lang-config">ScriptAlias "/cgi-bin/" "/usr/local/apache2/cgi-bin/"
54 VirtualScriptAlias "/never/found/%0/cgi-bin/"</pre>
55
56     </div>
57 </div>
58 <div id="quickview"><h3>Topics</h3>
59 <ul id="topics">
60 <li><img alt="" src="../images/down.gif" /> <a href="#interpol">Directory Name Interpolation</a></li>
61 <li><img alt="" src="../images/down.gif" /> <a href="#examples">Examples</a></li>
62 </ul><h3 class="directives">Directives</h3>
63 <ul id="toc">
64 <li><img alt="" src="../images/down.gif" /> <a href="#virtualdocumentroot">VirtualDocumentRoot</a></li>
65 <li><img alt="" src="../images/down.gif" /> <a href="#virtualdocumentrootip">VirtualDocumentRootIP</a></li>
66 <li><img alt="" src="../images/down.gif" /> <a href="#virtualscriptalias">VirtualScriptAlias</a></li>
67 <li><img alt="" src="../images/down.gif" /> <a href="#virtualscriptaliasip">VirtualScriptAliasIP</a></li>
68 </ul>
69 <h3>Bugfix checklist</h3><ul class="seealso"><li><a href="https://www.apache.org/dist/httpd/CHANGES_2.4">httpd changelog</a></li><li><a href="https://bz.apache.org/bugzilla/buglist.cgi?bug_status=__open__&amp;list_id=144532&amp;product=Apache%20httpd-2&amp;query_format=specific&amp;order=changeddate%20DESC%2Cpriority%2Cbug_severity&amp;component=mod_vhost_alias">Known issues</a></li><li><a href="https://bz.apache.org/bugzilla/enter_bug.cgi?product=Apache%20httpd-2&amp;component=mod_vhost_alias">Report a bug</a></li></ul><h3>See also</h3>
70 <ul class="seealso">
71 <li><code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code></li>
72 <li><a href="../vhosts/mass.html">Dynamically configured mass
73     virtual hosting</a></li>
74 <li><a href="#comments_section">Comments</a></li></ul></div>
75 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
76 <div class="section">
77 <h2><a name="interpol" id="interpol">Directory Name Interpolation</a></h2>
78     
79
80     <p>All the directives in this module interpolate a string into
81     a pathname. The interpolated string (henceforth called the
82     "name") may be either the server name (see the <code class="directive"><a href="../mod/core.html#usecanonicalname">UseCanonicalName</a></code>
83     directive for details on how this is determined) or the IP
84     address of the virtual host on the server in dotted-quad
85     format. The interpolation is controlled by specifiers inspired
86     by <code>printf</code> which have a number of formats:</p>
87
88 <table>
89
90 <tr><td><code>%%</code></td>
91 <td>insert a <code>%</code></td></tr>
92
93 <tr><td><code>%p</code></td>
94 <td>insert the port number of the virtual host</td></tr>
95
96 <tr><td><code>%N.M</code></td>
97 <td>insert (part of) the name</td></tr>
98
99 </table>
100
101     <p><code>N</code> and <code>M</code> are used to specify
102     substrings of the name. <code>N</code> selects from the
103     dot-separated components of the name, and <code>M</code>
104     selects characters within whatever <code>N</code> has selected.
105     <code>M</code> is optional and defaults to zero if it isn't
106     present; the dot must be present if and only if <code>M</code>
107     is present. The interpretation is as follows:</p>
108
109     <table>
110       
111       <tr><td><code>0</code></td>
112       <td>the whole name</td></tr>
113
114       <tr><td><code>1</code></td>
115       <td>the first part</td></tr>
116
117       <tr><td><code>2</code></td>
118       <td>the second part</td></tr>
119
120       <tr><td><code>-1</code></td>
121       <td>the last part</td></tr>
122
123       <tr><td><code>-2</code></td>
124       <td>the penultimate part</td></tr>
125
126       <tr><td><code>2+</code></td>
127       <td>the second and all subsequent parts</td></tr>
128
129       <tr><td><code>-2+</code></td>
130       <td>the penultimate and all preceding parts</td></tr>
131
132       <tr><td><code>1+</code> and <code>-1+</code></td>
133       <td>the same as <code>0</code></td></tr>
134     </table>
135
136     <p>If <code>N</code> or <code>M</code> is greater than the number
137     of parts available a single underscore is interpolated. </p>
138
139 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
140 <div class="section">
141 <h2><a name="examples" id="examples">Examples</a></h2>
142     
143
144     <p>For simple name-based virtual hosts you might use the
145     following directives in your server configuration file:</p>
146
147     <pre class="prettyprint lang-config">UseCanonicalName    Off
148 VirtualDocumentRoot "/usr/local/apache/vhosts/%0"</pre>
149
150
151     <p>A request for
152     <code>http://www.example.com/directory/file.html</code> will be
153     satisfied by the file
154     <code>/usr/local/apache/vhosts/www.example.com/directory/file.html</code>.
155     </p>
156
157     <p>For a very large number of virtual hosts it is a good idea
158     to arrange the files to reduce the size of the
159     <code>vhosts</code> directory. To do this you might use the
160     following in your configuration file:</p>
161
162     <pre class="prettyprint lang-config">UseCanonicalName    Off
163 VirtualDocumentRoot "/usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2"</pre>
164
165
166     <p>A request for
167     <code>http://www.domain.example.com/directory/file.html</code>
168     will be satisfied by the file
169     <code>/usr/local/apache/vhosts/example.com/d/o/m/domain/directory/file.html</code>.</p>
170
171     <p>A more even spread of files can be achieved by hashing from the
172     end of the name, for example: </p>
173
174 <pre class="prettyprint lang-config">VirtualDocumentRoot "/usr/local/apache/vhosts/%3+/%2.-1/%2.-2/%2.-3/%2"</pre>
175
176
177     <p>The example request would come from
178     <code>/usr/local/apache/vhosts/example.com/n/i/a/domain/directory/file.html</code>.</p>
179
180     <p>Alternatively you might use: </p>
181
182 <pre class="prettyprint lang-config">VirtualDocumentRoot "/usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2.4+"</pre>
183
184
185     <p>The example request would come from
186     <code>/usr/local/apache/vhosts/example.com/d/o/m/ain/directory/file.html</code>.</p>
187
188 <p> A very common request by users is the ability to point multiple domains to multiple
189 document roots without having to worry about the length or number of parts of the
190 hostname being requested. If the requested hostname is <code>sub.www.domain.example.com</code>
191  instead of simply <code>www.domain.example.com</code>, then using %3+ will result in the document
192 root being <code>/usr/local/apache/vhosts/domain.example.com/...</code> instead of the
193 intended <code>example.com</code> directory. In such cases, it can be beneficial to use
194 the combination <code>%-2.0.%-1.0</code>, which will always yield the domain name and the
195 tld, for example <code>example.com</code> regardless of the number of subdomains appended
196 to the hostname. As such, one can make a configuration that will direct all first, second
197 or third level subdomains to the same directory:
198 </p>
199 <pre class="prettyprint lang-config">VirtualDocumentRoot "/usr/local/apache/vhosts/%-2.0.%-1.0"</pre>
200
201 <p>
202 In the example above, both <code>www.example.com</code> as well as <code>www.sub.example.com</code>
203 or <code>example.com</code> will all point to <code>/usr/local/apache/vhosts/example.com</code>.
204 </p>
205
206     <p>For IP-based virtual hosting you might use the following in
207     your configuration file:</p>
208
209     <pre class="prettyprint lang-config">UseCanonicalName DNS
210 VirtualDocumentRootIP "/usr/local/apache/vhosts/%1/%2/%3/%4/docs"
211 VirtualScriptAliasIP  "/usr/local/apache/vhosts/%1/%2/%3/%4/cgi-bin"</pre>
212
213
214     <p>A request for
215     <code>http://www.domain.example.com/directory/file.html</code>
216     would be satisfied by the file
217     <code>/usr/local/apache/vhosts/10/20/30/40/docs/directory/file.html</code>
218     if the IP address of <code>www.domain.example.com</code> were
219     10.20.30.40. A request for
220     <code>http://www.domain.example.com/cgi-bin/script.pl</code> would
221     be satisfied by executing the program
222     <code>/usr/local/apache/vhosts/10/20/30/40/cgi-bin/script.pl</code>.</p>
223
224     <p>If you want to include the <code>.</code> character in a
225     <code>VirtualDocumentRoot</code> directive, but it clashes with
226     a <code>%</code> directive, you can work around the problem in
227     the following way:</p>
228
229     <pre class="prettyprint lang-config">VirtualDocumentRoot "/usr/local/apache/vhosts/%2.0.%3.0"</pre>
230
231
232     <p>A request for
233     <code>http://www.domain.example.com/directory/file.html</code>
234     will be satisfied by the file
235     <code>/usr/local/apache/vhosts/domain.example/directory/file.html</code>.</p>
236
237     <p>The <code class="directive"><a href="../mod/mod_log_config.html#logformat">LogFormat</a></code>
238     directives <code>%V</code> and <code>%A</code> are useful
239     in conjunction with this module.</p>
240 </div>
241 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
242 <div class="directive-section"><h2><a name="VirtualDocumentRoot" id="VirtualDocumentRoot">VirtualDocumentRoot</a> <a name="virtualdocumentroot" id="virtualdocumentroot">Directive</a></h2>
243 <table class="directive">
244 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the document root
245 for a given virtual host</td></tr>
246 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualDocumentRoot <em>interpolated-directory</em>|none</code></td></tr>
247 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualDocumentRoot none</code></td></tr>
248 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
249 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
250 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
251 </table>
252
253     <p>The <code class="directive">VirtualDocumentRoot</code> directive allows you to
254     determine where Apache HTTP Server will find your documents based on the
255     value of the server name. The result of expanding
256     <em>interpolated-directory</em> is used as the root of the
257     document tree in a similar manner to the <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> directive's argument.
258     If <em>interpolated-directory</em> is <code>none</code> then
259     <code class="directive">VirtualDocumentRoot</code> is turned off. This directive
260     cannot be used in the same context as <code class="directive"><a href="#virtualdocumentrootip">VirtualDocumentRootIP</a></code>.</p>
261
262 <div class="warning"><h3>Note</h3>
263 <code class="directive">VirtualDocumentRoot</code> will override any <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> directives you may have put in the same
264 context or child contexts. Putting a <code class="directive">VirtualDocumentRoot</code>
265 in the global server scope will effectively override <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> directives in any virtual hosts defined later
266 on, unless you set <code class="directive">VirtualDocumentRoot</code> to <code>None</code>
267 in each virtual host.
268 </div>
269
270
271 </div>
272 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
273 <div class="directive-section"><h2><a name="VirtualDocumentRootIP" id="VirtualDocumentRootIP">VirtualDocumentRootIP</a> <a name="virtualdocumentrootip" id="virtualdocumentrootip">Directive</a></h2>
274 <table class="directive">
275 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the document root
276 for a given virtual host</td></tr>
277 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualDocumentRootIP <em>interpolated-directory</em>|none</code></td></tr>
278 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualDocumentRootIP none</code></td></tr>
279 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
280 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
281 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
282 </table>
283
284 <p>The <code class="directive">VirtualDocumentRootIP</code> directive is like the
285     <code class="directive"><a href="#virtualdocumentroot">VirtualDocumentRoot</a></code>
286     directive, except that it uses the IP address of the server end
287     of the connection for directory interpolation instead of the server
288     name.</p>
289
290 </div>
291 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
292 <div class="directive-section"><h2><a name="VirtualScriptAlias" id="VirtualScriptAlias">VirtualScriptAlias</a> <a name="virtualscriptalias" id="virtualscriptalias">Directive</a></h2>
293 <table class="directive">
294 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the CGI directory for
295 a given virtual host</td></tr>
296 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualScriptAlias <em>interpolated-directory</em>|none</code></td></tr>
297 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualScriptAlias none</code></td></tr>
298 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
299 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
300 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
301 </table>
302
303     <p>The <code class="directive">VirtualScriptAlias</code> directive allows you to
304     determine where Apache httpd will find CGI scripts in a similar
305     manner to <code class="directive"><a href="#virtualdocumentroot">VirtualDocumentRoot</a></code> does for other documents. It matches
306     requests for URIs starting <code>/cgi-bin/</code>, much like <code class="directive"><a href="../mod/mod_alias.html#scriptalias">ScriptAlias</a></code>
307     <code>/cgi-bin/</code> would.</p>
308
309
310 </div>
311 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
312 <div class="directive-section"><h2><a name="VirtualScriptAliasIP" id="VirtualScriptAliasIP">VirtualScriptAliasIP</a> <a name="virtualscriptaliasip" id="virtualscriptaliasip">Directive</a></h2>
313 <table class="directive">
314 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Dynamically configure the location of the CGI directory for
315 a given virtual host</td></tr>
316 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>VirtualScriptAliasIP <em>interpolated-directory</em>|none</code></td></tr>
317 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>VirtualScriptAliasIP none</code></td></tr>
318 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr>
319 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr>
320 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_vhost_alias</td></tr>
321 </table>
322
323     <p>The <code class="directive">VirtualScriptAliasIP</code> directive is like the
324     <code class="directive"><a href="#virtualscriptalias">VirtualScriptAlias</a></code>
325     directive, except that it uses the IP address of the server end
326     of the connection for directory interpolation instead of the server
327     name.</p>
328
329     
330 </div>
331 </div>
332 <div class="bottomlang">
333 <p><span>Available Languages: </span><a href="../en/mod/mod_vhost_alias.html" title="English">&nbsp;en&nbsp;</a> |
334 <a href="../tr/mod/mod_vhost_alias.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
335 </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>
336 <script type="text/javascript"><!--//--><![CDATA[//><!--
337 var comments_shortname = 'httpd';
338 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_vhost_alias.html';
339 (function(w, d) {
340     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
341         d.write('<div id="comments_thread"><\/div>');
342         var s = d.createElement('script');
343         s.type = 'text/javascript';
344         s.async = true;
345         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
346         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
347     }
348     else {
349         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
350     }
351 })(window, document);
352 //--><!]]></script></div><div id="footer">
353 <p class="apache">Copyright 2016 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>
354 <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[//><!--
355 if (typeof(prettyPrint) !== 'undefined') {
356     prettyPrint();
357 }
358 //--><!]]></script>
359 </body></html>