2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
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
14 http://www.apache.org/licenses/LICENSE-2.0
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.
23 <modulesynopsis metafile="mod_macro.xml.meta">
25 <name>mod_macro</name>
26 <description>Provides macros within apache httpd runtime configuration files</description>
28 <sourcefile>mod_macro.c</sourcefile>
29 <identifier>macro_module</identifier>
33 <p>Provides macros within Apache httpd runtime configuration files,
34 to ease the process of creating numerous similar configuration
35 blocks. When the server starts up, the macros are expanded using the
36 provided parameters, and the result is processed as along with the
37 rest of the configuration file.</p>
41 <section id="usage"><title>Usage</title>
43 <p>Macros are defined using <directive module="mod_macro"
44 type="section">Macro</directive> blocks, which contain the portion of
45 your configuration that needs to be repeated, complete with variables
46 for those parts that will need to be substituted.</p>
48 <p>For example, you might use a macro to define a <directive module="core"
49 type="section">VirtualHost</directive> block, in order to define
50 multiple similar virtual hosts:</p>
52 <highlight language="config">
53 <Macro VHost $name $domain>
54 <VirtualHost *:80>
56 ServerAlias www.$domain
58 DocumentRoot "/var/www/vhosts/$name"
59 ErrorLog "/var/log/httpd/$name.error_log"
60 CustomLog "/var/log/httpd/$name.access_log" combined
65 <p>Macro names are case-insensitive, like httpd configuration
66 directives. However, variable names are case sensitive.</p>
68 <p>You would then invoke this macro several times to create virtual
71 <highlight language="config">
72 Use VHost example example.com
73 Use VHost myhost hostname.org
74 Use VHost apache apache.org
79 <p>At server startup time, each of these <directive module="mod_macro">Use</directive>
80 invocations would be expanded into a full virtualhost, as
81 described by the <directive module="mod_macro" type="section">Macro</directive>
84 <p>The <directive module="mod_macro">UndefMacro</directive> directive is
85 used so that later macros using the same variable names don't result in
86 conflicting definitions.</p>
88 <p>A more elaborate version of this example may be seen below in the
93 <section id="tips"><title>Tips</title>
95 <p>Parameter names should begin with a sigil such as <code>$</code>,
96 <code>%</code>, or <code>@</code>, so that they are clearly
97 identifiable, and also in order to help deal with interactions with
98 other directives, such as the core <directive
99 module="core">Define</directive> directive. Failure to do so will
100 result in a warning. Nevertheless, you are encouraged to have a good
101 knowledge of your entire server configuration in order to avoid reusing
102 the same variables in different scopes, which can cause confusion.</p>
104 <p>Parameters prefixed with either <code>$</code> or <code>%</code> are
105 not escaped. Parameters prefixes with <code>@</code> are escaped in
108 <p>Avoid using a parameter which contains another parameter as a prefix,
109 (For example, <code>$win</code> and <code>$winter</code>) as this may
110 cause confusion at expression evaluation time. In the event of such
111 confusion, the longest possible parameter name is used.</p>
113 <p>If you want to use a value within another string, it is useful to
114 surround the parameter in braces, to avoid confusion:</p>
116 <highlight language="config">
117 <Macro DocRoot ${docroot}>
118 DocumentRoot "/var/www/${docroot}/htdocs"
124 <section id="examples">
125 <title>Examples</title>
128 <title>Virtual Host Definition</title>
130 <p>A common usage of <module>mod_macro</module> is for the creation of
131 dynamically-generated virtual hosts.</p>
133 <highlight language="config">
134 ## Define a VHost Macro for repetitive configurations
136 <Macro VHost $host $port $dir>
138 <VirtualHost *:$port>
143 # Public document root
144 <Directory "$dir">
148 # limit access to intranet subdir.
149 <Directory "$dir/intranet">
150 Require ip 10.0.0.0/8
155 ## Use of VHost with different arguments.
157 Use VHost www.apache.org 80 /vhosts/apache/htdocs
158 Use VHost example.org 8080 /vhosts/example/htdocs
159 Use VHost www.example.fr 1234 /vhosts/example.fr/htdocs
161 </section> <!-- Vhosts -->
164 <title>Removal of a macro definition</title>
166 <p>It's recommended that you undefine a macro once you've used it. This
167 avoids confusion in a complex configuration file where there may be
168 conflicts in variable names.</p>
170 <highlight language="config">
171 <Macro DirGroup $dir $group>
172 <Directory "$dir">
177 Use DirGroup /www/apache/private private
178 Use DirGroup /www/apache/server admin
183 </section> <!-- UndefMacro -->
185 </section> <!-- Example -->
188 <directivesynopsis type="section">
190 <description>Define a configuration file macro</description>
192 <Macro <var>name</var> [<var>par1</var> .. <var>parN</var>]>
193 ... </Macro></syntax>
195 <context>server config</context>
196 <context>virtual host</context>
197 <context>directory</context>
199 <override>All</override>
202 <p>The <directive type="section">Macro</directive> directive controls the
203 definition of a macro within the server runtime configuration files.
204 The first argument is the name of the macro.
205 Other arguments are parameters to the macro. It is good practice to prefix
206 parameter names with any of '<code>$%@</code>', and not macro names
207 with such characters.
210 <highlight language="config">
211 <Macro LocalAccessPolicy>
212 Require ip 10.2.16.0/24
215 <Macro RestrictedAccessPolicy $ipnumbers>
216 Require ip $ipnumbers
225 <description>Use a macro</description>
226 <syntax>Use <var>name</var> [<var>value1</var> ... <var>valueN</var>]
229 <context>server config</context>
230 <context>virtual host</context>
231 <context>directory</context>
233 <override>All</override>
236 <p>The <directive>Use</directive> directive controls the use of a macro.
237 The specified macro is expanded. It must be given the same number of
238 arguments as in the macro definition. The provided values are
239 associated to their corresponding initial parameters and are substituted
240 before processing.</p>
242 <highlight language="config">
243 Use LocalAccessPolicy
245 Use RestrictedAccessPolicy "192.54.172.0/24 192.54.148.0/24"
248 <p>is equivalent, with the macros defined above, to:</p>
250 <highlight language="config">
251 Require ip 10.2.16.0/24
253 Require ip 192.54.172.0/24 192.54.148.0/24
261 <name>UndefMacro</name>
262 <description>Undefine a macro</description>
264 <syntax>UndefMacro <var>name</var></syntax>
266 <context>server config</context>
267 <context>virtual host</context>
268 <context>directory</context>
270 <override>All</override>
273 <p>The <directive>UndefMacro</directive> directive undefines a macro
274 which has been defined before hand.</p>
276 <highlight language="config">
277 UndefMacro LocalAccessPolicy
278 UndefMacro RestrictedAccessPolicy
283 <!-- MacroIgnoreEmptyArg -->
285 <name>MacroIgnoreEmptyArgs</name>
286 <description>Ignore warnings, and does not log, about empty Macro argument(s)</description>
288 <syntax>MacroIgnoreEmptyArgs</syntax>
290 <context>server config</context>
291 <context>virtual host</context>
292 <context>directory</context>
294 <override>All</override>
298 <!-- MacroIgnoreBadNesting -->
300 <name>MacroIgnoreBadNesting</name>
301 <description>Ignore warnings, and does not log, about bad nesting of Macros</description>
303 <syntax>MacroIgnoreBadNesting</syntax>
305 <context>server config</context>
306 <context>virtual host</context>
307 <context>directory</context>
309 <override>All</override>