]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_vhost_alias.xml
Rebuild.
[apache] / docs / manual / mod / mod_vhost_alias.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
22
23 <modulesynopsis metafile="mod_vhost_alias.xml.meta">
24
25 <name>mod_vhost_alias</name>
26 <description>Provides for dynamically configured mass virtual
27 hosting</description>
28 <status>Extension</status>
29 <sourcefile>mod_vhost_alias.c</sourcefile>
30 <identifier>vhost_alias_module</identifier>
31
32 <summary>
33     <p>This module creates dynamically configured virtual hosts, by
34     allowing the IP address and/or the <code>Host:</code> header of
35     the HTTP request to be used as part of the pathname to
36     determine what files to serve. This allows for easy use of a
37     huge number of virtual hosts with similar configurations.</p>
38
39     <note><title>Note</title>
40       <p>If <module>mod_alias</module> or <module>mod_userdir</module> are
41       used for translating URIs to filenames, they will override the
42       directives of <module>mod_vhost_alias</module> described below. For
43       example, the following configuration will map <code>
44       /cgi-bin/script.pl</code> to <code>
45       /usr/local/apache2/cgi-bin/script.pl</code> in all cases:</p>
46
47       <highlight language="config">
48 ScriptAlias "/cgi-bin/" "/usr/local/apache2/cgi-bin/"
49 VirtualScriptAlias "/never/found/%0/cgi-bin/"
50       </highlight>
51     </note>
52 </summary>
53
54 <seealso><directive module="core">UseCanonicalName</directive></seealso>
55 <seealso><a href="../vhosts/mass.html">Dynamically configured mass
56     virtual hosting</a></seealso>
57
58 <section id="interpol">
59     <title>Directory Name Interpolation</title>
60
61     <p>All the directives in this module interpolate a string into
62     a pathname. The interpolated string (henceforth called the
63     "name") may be either the server name (see the <directive
64     module="core">UseCanonicalName</directive>
65     directive for details on how this is determined) or the IP
66     address of the virtual host on the server in dotted-quad
67     format. The interpolation is controlled by specifiers inspired
68     by <code>printf</code> which have a number of formats:</p>
69
70 <table>
71 <columnspec><column width=".2"/><column width=".6"/></columnspec>
72 <tr><td><code>%%</code></td>
73 <td>insert a <code>%</code></td></tr>
74
75 <tr><td><code>%p</code></td>
76 <td>insert the port number of the virtual host</td></tr>
77
78 <tr><td><code>%N.M</code></td>
79 <td>insert (part of) the name</td></tr>
80
81 </table>
82
83     <p><code>N</code> and <code>M</code> are used to specify
84     substrings of the name. <code>N</code> selects from the
85     dot-separated components of the name, and <code>M</code>
86     selects characters within whatever <code>N</code> has selected.
87     <code>M</code> is optional and defaults to zero if it isn't
88     present; the dot must be present if and only if <code>M</code>
89     is present. The interpretation is as follows:</p>
90
91     <table>
92       <columnspec><column width=".1"/><column width=".4"/></columnspec>
93       <tr><td><code>0</code></td>
94       <td>the whole name</td></tr>
95
96       <tr><td><code>1</code></td>
97       <td>the first part</td></tr>
98
99       <tr><td><code>2</code></td>
100       <td>the second part</td></tr>
101
102       <tr><td><code>-1</code></td>
103       <td>the last part</td></tr>
104
105       <tr><td><code>-2</code></td>
106       <td>the penultimate part</td></tr>
107
108       <tr><td><code>2+</code></td>
109       <td>the second and all subsequent parts</td></tr>
110
111       <tr><td><code>-2+</code></td>
112       <td>the penultimate and all preceding parts</td></tr>
113
114       <tr><td><code>1+</code> and <code>-1+</code></td>
115       <td>the same as <code>0</code></td></tr>
116     </table>
117
118     <p>If <code>N</code> or <code>M</code> is greater than the number
119     of parts available a single underscore is interpolated. </p>
120
121 </section>
122
123 <section id="examples">
124     <title>Examples</title>
125
126     <p>For simple name-based virtual hosts you might use the
127     following directives in your server configuration file:</p>
128
129     <highlight language="config">
130 UseCanonicalName    Off
131 VirtualDocumentRoot "/usr/local/apache/vhosts/%0"
132     </highlight>
133
134     <p>A request for
135     <code>http://www.example.com/directory/file.html</code> will be
136     satisfied by the file
137     <code>/usr/local/apache/vhosts/www.example.com/directory/file.html</code>.
138     </p>
139
140     <p>For a very large number of virtual hosts it is a good idea
141     to arrange the files to reduce the size of the
142     <code>vhosts</code> directory. To do this you might use the
143     following in your configuration file:</p>
144
145     <highlight language="config">
146 UseCanonicalName    Off
147 VirtualDocumentRoot "/usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2"
148     </highlight>
149
150     <p>A request for
151     <code>http://www.domain.example.com/directory/file.html</code>
152     will be satisfied by the file
153     <code>/usr/local/apache/vhosts/example.com/d/o/m/domain/directory/file.html</code>.</p>
154
155     <p>A more even spread of files can be achieved by hashing from the
156     end of the name, for example: </p>
157
158 <highlight language="config">
159 VirtualDocumentRoot "/usr/local/apache/vhosts/%3+/%2.-1/%2.-2/%2.-3/%2"
160 </highlight>
161
162     <p>The example request would come from
163     <code>/usr/local/apache/vhosts/example.com/n/i/a/domain/directory/file.html</code>.</p>
164
165     <p>Alternatively you might use: </p>
166
167 <highlight language="config">
168 VirtualDocumentRoot "/usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2.4+"
169 </highlight>
170
171     <p>The example request would come from
172     <code>/usr/local/apache/vhosts/example.com/d/o/m/ain/directory/file.html</code>.</p>
173
174 <p> A very common request by users is the ability to point multiple domains to multiple
175 document roots without having to worry about the length or number of parts of the
176 hostname being requested. If the requested hostname is <code>sub.www.domain.example.com</code>
177  instead of simply <code>www.domain.example.com</code>, then using %3+ will result in the document
178 root being <code>/usr/local/apache/vhosts/domain.example.com/...</code> instead of the
179 intended <code>example.com</code> directory. In such cases, it can be beneficial to use
180 the combination <code>%-2.0.%-1.0</code>, which will always yield the domain name and the
181 tld, for example <code>example.com</code> regardless of the number of subdomains appended
182 to the hostname. As such, one can make a configuration that will direct all first, second
183 or third level subdomains to the same directory:
184 </p>
185 <highlight language="config">
186 VirtualDocumentRoot "/usr/local/apache/vhosts/%-2.0.%-1.0"
187 </highlight>
188 <p>
189 In the example above, both <code>www.example.com</code> as well as <code>www.sub.example.com</code>
190 or <code>example.com</code> will all point to <code>/usr/local/apache/vhosts/example.com</code>.
191 </p>
192
193     <p>For IP-based virtual hosting you might use the following in
194     your configuration file:</p>
195
196     <highlight language="config">
197 UseCanonicalName DNS
198 VirtualDocumentRootIP "/usr/local/apache/vhosts/%1/%2/%3/%4/docs"
199 VirtualScriptAliasIP  "/usr/local/apache/vhosts/%1/%2/%3/%4/cgi-bin"
200     </highlight>
201
202     <p>A request for
203     <code>http://www.domain.example.com/directory/file.html</code>
204     would be satisfied by the file
205     <code>/usr/local/apache/vhosts/10/20/30/40/docs/directory/file.html</code>
206     if the IP address of <code>www.domain.example.com</code> were
207     10.20.30.40. A request for
208     <code>http://www.domain.example.com/cgi-bin/script.pl</code> would
209     be satisfied by executing the program
210     <code>/usr/local/apache/vhosts/10/20/30/40/cgi-bin/script.pl</code>.</p>
211
212     <p>If you want to include the <code>.</code> character in a
213     <code>VirtualDocumentRoot</code> directive, but it clashes with
214     a <code>%</code> directive, you can work around the problem in
215     the following way:</p>
216
217     <highlight language="config">
218 VirtualDocumentRoot "/usr/local/apache/vhosts/%2.0.%3.0"
219     </highlight>
220
221     <p>A request for
222     <code>http://www.domain.example.com/directory/file.html</code>
223     will be satisfied by the file
224     <code>/usr/local/apache/vhosts/domain.example/directory/file.html</code>.</p>
225
226     <p>The <directive module="mod_log_config">LogFormat</directive>
227     directives <code>%V</code> and <code>%A</code> are useful
228     in conjunction with this module.</p>
229 </section>
230
231 <directivesynopsis>
232 <name>VirtualDocumentRoot</name>
233 <description>Dynamically configure the location of the document root
234 for a given virtual host</description>
235 <syntax>VirtualDocumentRoot <em>interpolated-directory</em>|none</syntax>
236 <default>VirtualDocumentRoot none</default>
237 <contextlist>
238 <context>server config</context>
239 <context>virtual host</context>
240 </contextlist>
241
242 <usage>
243
244     <p>The <directive>VirtualDocumentRoot</directive> directive allows you to
245     determine where Apache HTTP Server will find your documents based on the
246     value of the server name. The result of expanding
247     <em>interpolated-directory</em> is used as the root of the
248     document tree in a similar manner to the <directive
249     module="core">DocumentRoot</directive> directive's argument.
250     If <em>interpolated-directory</em> is <code>none</code> then
251     <directive>VirtualDocumentRoot</directive> is turned off. This directive
252     cannot be used in the same context as <directive
253     module="mod_vhost_alias">VirtualDocumentRootIP</directive>.</p>
254
255 <note type="warning"><title>Note</title>
256 <directive>VirtualDocumentRoot</directive> will override any <directive
257 module="core">DocumentRoot</directive> directives you may have put in the same
258 context or child contexts. Putting a <directive>VirtualDocumentRoot</directive>
259 in the global server scope will effectively override <directive
260 module="core">DocumentRoot</directive> directives in any virtual hosts defined later
261 on, unless you set <directive>VirtualDocumentRoot</directive> to <code>None</code>
262 in each virtual host.
263 </note>
264
265 </usage>
266
267 </directivesynopsis>
268
269 <directivesynopsis>
270 <name>VirtualDocumentRootIP</name>
271 <description>Dynamically configure the location of the document root
272 for a given virtual host</description>
273 <syntax>VirtualDocumentRootIP <em>interpolated-directory</em>|none</syntax>
274 <default>VirtualDocumentRootIP none</default>
275 <contextlist>
276 <context>server config</context>
277 <context>virtual host</context>
278 </contextlist>
279
280 <usage>
281
282 <p>The <directive>VirtualDocumentRootIP</directive> directive is like the
283     <directive module="mod_vhost_alias">VirtualDocumentRoot</directive>
284     directive, except that it uses the IP address of the server end
285     of the connection for directory interpolation instead of the server
286     name.</p>
287 </usage>
288 </directivesynopsis>
289
290 <directivesynopsis>
291 <name>VirtualScriptAlias</name>
292 <description>Dynamically configure the location of the CGI directory for
293 a given virtual host</description>
294 <syntax>VirtualScriptAlias <em>interpolated-directory</em>|none</syntax>
295 <default>VirtualScriptAlias none</default>
296 <contextlist>
297 <context>server config</context>
298 <context>virtual host</context>
299 </contextlist>
300
301 <usage>
302
303     <p>The <directive>VirtualScriptAlias</directive> directive allows you to
304     determine where Apache httpd will find CGI scripts in a similar
305     manner to <directive module="mod_vhost_alias"
306     >VirtualDocumentRoot</directive> does for other documents. It matches
307     requests for URIs starting <code>/cgi-bin/</code>, much like <directive
308     module="mod_alias">ScriptAlias</directive>
309     <code>/cgi-bin/</code> would.</p>
310
311 </usage>
312 </directivesynopsis>
313
314 <directivesynopsis>
315 <name>VirtualScriptAliasIP</name>
316 <description>Dynamically configure the location of the CGI directory for
317 a given virtual host</description>
318 <syntax>VirtualScriptAliasIP <em>interpolated-directory</em>|none</syntax>
319 <default>VirtualScriptAliasIP none</default>
320 <contextlist>
321 <context>server config</context>
322 <context>virtual host</context>
323 </contextlist>
324
325 <usage>
326
327     <p>The <directive>VirtualScriptAliasIP</directive> directive is like the
328     <directive module="mod_vhost_alias">VirtualScriptAlias</directive>
329     directive, except that it uses the IP address of the server end
330     of the connection for directory interpolation instead of the server
331     name.</p>
332
333     </usage>
334
335 </directivesynopsis>
336 </modulesynopsis>