2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
6 Copyright 2002-2004 The Apache Software Foundation
8 Licensed under the Apache License, Version 2.0 (the "License");
9 you may not use this file except in compliance with the License.
10 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
14 Unless required by applicable law or agreed to in writing, software
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
21 <modulesynopsis metafile="mod_vhost_alias.xml.meta">
23 <name>mod_vhost_alias</name>
24 <description>Provides for dynamically configured mass virtual
26 <status>Extension</status>
27 <sourcefile>mod_vhost_alias.c</sourcefile>
28 <identifier>vhost_alias_module</identifier>
31 <p>This module creates dynamically configured virtual hosts, by
32 allowing the IP address and/or the <code>Host:</code> header of
33 the HTTP request to be used as part of the pathname to
34 determine what files to serve. This allows for easy use of a
35 huge number of virtual hosts with similar configurations.</p>
37 <note><title>Note</title>
38 <p>If <module>mod_alias</module> or <module>mod_userdir</module> are
39 used for translating URIs to filenames, they will override the
40 directives of <module>mod_vhost_alias</module> described below. For
41 example, the following configuration will map <code>
42 /cgi-bin/script.pl</code> to <code>
43 /usr/local/apache2/cgi-bin/script.pl</code> in all cases:</p>
46 ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/<br />
47 VirtualScriptAlias /never/found/%0/cgi-bin/
52 <seealso><directive module="core">UseCanonicalName</directive></seealso>
53 <seealso><a href="../vhosts/mass.html">Dynamically configured mass
54 virtual hosting</a></seealso>
56 <section id="interpol">
57 <title>Directory Name Interpolation</title>
59 <p>All the directives in this module interpolate a string into
60 a pathname. The interpolated string (henceforth called the
61 "name") may be either the server name (see the <directive
62 module="core">UseCanonicalName</directive>
63 directive for details on how this is determined) or the IP
64 address of the virtual host on the server in dotted-quad
65 format. The interpolation is controlled by specifiers inspired
66 by <code>printf</code> which have a number of formats:</p>
70 <tr><td><code>%%</code></td>
71 <td>insert a <code>%</code></td></tr>
73 <tr><td><code>%p</code></td>
74 <td>insert the port number of the virtual host</td></tr>
76 <tr><td><code>%N.M</code></td>
77 <td>insert (part of) the name</td></tr>
81 <p><code>N</code> and <code>M</code> are used to specify
82 substrings of the name. <code>N</code> selects from the
83 dot-separated components of the name, and <code>M</code>
84 selects characters within whatever <code>N</code> has selected.
85 <code>M</code> is optional and defaults to zero if it isn't
86 present; the dot must be present if and only if <code>M</code>
87 is present. The interpretation is as follows:</p>
90 <tr><td><code>0</code></td>
91 <td>the whole name</td></tr>
93 <tr><td><code>1</code></td>
94 <td>the first part</td></tr>
96 <tr><td><code>2</code></td>
97 <td>the second part</td></tr>
99 <tr><td><code>-1</code></td>
100 <td>the last part</td></tr>
102 <tr><td><code>-2</code></td>
103 <td>the penultimate part</td></tr>
105 <tr><td><code>2+</code></td>
106 <td>the second and all subsequent parts</td></tr>
108 <tr><td><code>-2+</code></td>
109 <td>the penultimate and all preceding parts</td></tr>
111 <tr><td><code>1+</code> and <code>-1+</code></td>
112 <td>the same as <code>0</code></td></tr>
115 <p>If <code>N</code> or <code>M</code> is greater than the number
116 of parts available a single underscore is interpolated. </p>
120 <section id="examples">
121 <title>Examples</title>
123 <p>For simple name-based virtual hosts you might use the
124 following directives in your server configuration file:</p>
127 UseCanonicalName Off<br />
128 VirtualDocumentRoot /usr/local/apache/vhosts/%0
132 <code>http://www.example.com/directory/file.html</code> will be
133 satisfied by the file
134 <code>/usr/local/apache/vhosts/www.example.com/directory/file.html</code>.
137 <p>For a very large number of virtual hosts it is a good idea
138 to arrange the files to reduce the size of the
139 <code>vhosts</code> directory. To do this you might use the
140 following in your configuration file:</p>
143 UseCanonicalName Off<br />
144 VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2
148 <code>http://www.domain.example.com/directory/file.html</code>
149 will be satisfied by the file
150 <code>/usr/local/apache/vhosts/example.com/d/o/m/domain/directory/file.html</code>.</p>
152 <p>A more even spread of files can be achieved by hashing from the
153 end of the name, for example: </p>
156 VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.-1/%2.-2/%2.-3/%2
159 <p>The example request would come from
160 <code>/usr/local/apache/vhosts/example.com/n/i/a/domain/directory/file.html</code>.</p>
162 <p>Alternatively you might use: </p>
165 VirtualDocumentRoot /usr/local/apache/vhosts/%3+/%2.1/%2.2/%2.3/%2.4+
168 <p>The example request would come from
169 <code>/usr/local/apache/vhosts/example.com/d/o/m/ain/directory/file.html</code>.</p>
171 <p>For IP-based virtual hosting you might use the following in
172 your configuration file:</p>
175 UseCanonicalName DNS<br />
176 VirtualDocumentRootIP /usr/local/apache/vhosts/%1/%2/%3/%4/docs<br />
177 VirtualScriptAliasIP /usr/local/apache/vhosts/%1/%2/%3/%4/cgi-bin
181 <code>http://www.domain.example.com/directory/file.html</code>
182 would be satisfied by the file
183 <code>/usr/local/apache/vhosts/10/20/30/40/docs/directory/file.html</code>
184 if the IP address of <code>www.domain.example.com</code> were
185 10.20.30.40. A request for
186 <code>http://www.domain.example.com/cgi-bin/script.pl</code> would
187 be satisfied by executing the program
188 <code>/usr/local/apache/vhosts/10/20/30/40/cgi-bin/script.pl</code>.</p>
190 <p>If you want to include the <code>.</code> character in a
191 <code>VirtualDocumentRoot</code> directive, but it clashes with
192 a <code>%</code> directive, you can work around the problem in
193 the following way:</p>
196 VirtualDocumentRoot /usr/local/apache/vhosts/%2.0.%3.0
200 <code>http://www.domain.example.com/directory/file.html</code>
201 will be satisfied by the file
202 <code>/usr/local/apache/vhosts/domain.example/directory/file.html</code>.</p>
204 <p>The <directive module="mod_log_config">LogFormat</directive>
205 directives <code>%V</code> and <code>%A</code> are useful
206 in conjunction with this module.</p>
210 <name>VirtualDocumentRoot</name>
211 <description>Dynamically configure the location of the document root
212 for a given virtual host</description>
213 <syntax>VirtualDocumentRoot <em>interpolated-directory</em>|none</syntax>
214 <default>VirtualDocumentRoot none</default>
216 <context>server config</context>
217 <context>virtual host</context>
222 <p>The <directive>VirtualDocumentRoot</directive> directive allows you to
223 determine where Apache will find your documents based on the
224 value of the server name. The result of expanding
225 <em>interpolated-directory</em> is used as the root of the
226 document tree in a similar manner to the <directive
227 module="core">DocumentRoot</directive> directive's argument.
228 If <em>interpolated-directory</em> is <code>none</code> then
229 <directive>VirtualDocumentRoot</directive> is turned off. This directive
230 cannot be used in the same context as <directive
231 module="mod_vhost_alias">VirtualDocumentRootIP</directive>.</p>
237 <name>VirtualDocumentRootIP</name>
238 <description>Dynamically configure the location of the document root
239 for a given virtual host</description>
240 <syntax>VirtualDocumentRootIP <em>interpolated-directory</em>|none</syntax>
241 <default>VirtualDocumentRootIP none</default>
243 <context>server config</context>
244 <context>virtual host</context>
249 <p>The <directive>VirtualDocumentRootIP</directive> directive is like the
250 <directive module="mod_vhost_alias">VirtualDocumentRoot</directive>
251 directive, except that it uses the IP address of the server end
252 of the connection for directory interpolation instead of the server
258 <name>VirtualScriptAlias</name>
259 <description>Dynamically configure the location of the CGI directory for
260 a given virtual host</description>
261 <syntax>VirtualScriptAlias <em>interpolated-directory</em>|none</syntax>
262 <default>VirtualScriptAlias none</default>
264 <context>server config</context>
265 <context>virtual host</context>
270 <p>The <directive>VirtualScriptAlias</directive> directive allows you to
271 determine where Apache will find CGI scripts in a similar
272 manner to <directive module="mod_vhost_alias"
273 >VirtualDocumentRoot</directive> does for other documents. It matches
274 requests for URIs starting <code>/cgi-bin/</code>, much like <directive
275 module="mod_alias">ScriptAlias</directive>
276 <code>/cgi-bin/</code> would.</p>
282 <name>VirtualScriptAliasIP</name>
283 <description>Dynamically configure the location of the cgi directory for
284 a given virtual host</description>
285 <syntax>VirtualScriptAliasIP <em>interpolated-directory</em>|none</syntax>
286 <default>VirtualScriptAliasIP none</default>
288 <context>server config</context>
289 <context>virtual host</context>
294 <p>The <directive>VirtualScriptAliasIP</directive> directive is like the
295 <directive module="mod_vhost_alias">VirtualScriptAlias</directive>
296 directive, except that it uses the IP address of the server end
297 of the connection for directory interpolation instead of the server