mod_macro.html.en revision 205f749042ed530040a4f0080dbcb47ceae8a374
0N/A<?xml version="1.0" encoding="ISO-8859-1"?>
1472N/A<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
0N/A<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
0N/A XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0N/A This file is generated from xml source: DO NOT EDIT
0N/A XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0N/A -->
0N/A<title>mod_macro - Apache HTTP Server Version 2.5</title>
0N/A<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
0N/A<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
0N/A<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" />
0N/A<script src="/style/scripts/prettify.min.js" type="text/javascript">
0N/A</script>
0N/A
0N/A<link href="/images/favicon.ico" rel="shortcut icon" /></head>
0N/A<body>
0N/A<div id="page-header">
0N/A<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>
1472N/A<p class="apache">Apache HTTP Server Version 2.5</p>
1472N/A<img alt="" src="/images/feather.gif" /></div>
1472N/A<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
0N/A<div id="path">
0N/A<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>
0N/A<div id="page-content">
0N/A<div id="preamble"><h1>Apache Module mod_macro</h1>
0N/A<div class="toplang">
0N/A<p><span>Available Languages: </span><a href="/en/mod/mod_macro.html" title="English">&nbsp;en&nbsp;</a> |
0N/A<a href="/fr/mod/mod_macro.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
0N/A</div>
0N/A<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides macros within apache httpd runtime configuration files</td></tr>
0N/A<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
0N/A<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>macro_module</td></tr>
0N/A<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_macro.c</td></tr></table>
0N/A<h3>Summary</h3>
0N/A
0N/A
0N/A <p>Provides macros within Apache httpd runtime configuration files,
0N/A to ease the process of creating numerous similar configuration
0N/A blocks. When the server starts up, the macros are expanded using the
0N/A provided parameters, and the result is processed as along with the
0N/A rest of the configuration file.</p>
0N/A
0N/A</div>
0N/A<div id="quickview"><h3 class="directives">Directives</h3>
0N/A<ul id="toc">
0N/A<li><img alt="" src="/images/down.gif" /> <a href="#macro">&lt;Macro&gt;</a></li>
0N/A<li><img alt="" src="/images/down.gif" /> <a href="#undefmacro">UndefMacro</a></li>
0N/A<li><img alt="" src="/images/down.gif" /> <a href="#use">Use</a></li>
0N/A</ul>
0N/A<h3>Topics</h3>
29N/A<ul id="topics">
0N/A<li><img alt="" src="/images/down.gif" /> <a href="#usage">Usage</a></li>
0N/A<li><img alt="" src="/images/down.gif" /> <a href="#tips">Tips</a></li>
0N/A<li><img alt="" src="/images/down.gif" /> <a href="#examples">Examples</a></li>
0N/A</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
0N/A<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0N/A<div class="section">
0N/A<h2><a name="usage" id="usage">Usage</a></h2>
0N/A
0N/A<p>Macros are defined using <code class="directive">&lt;Macro&gt;</code> blocks, which contain the portion of
0N/Ayour configuration that needs to be repeated, complete with variables
0N/Afor those parts that will need to be substituted.</p>
0N/A
0N/A<p>For example, you might use a macro to define a <code class="directive">&lt;VirtualHost&gt;</code> block, in order to define
0N/Amultiple similar virtual hosts:</p>
0N/A
0N/A<pre class="prettyprint lang-config">&lt;Macro VHost $name $domain&gt;
0N/A&lt;VirtualHost *:80&gt;
0N/A ServerName $domain
0N/A ServerAlias www.$domain
0N/A
0N/A DocumentRoot /var/www/vhosts/$name
0N/A ErrorLog /var/log/httpd/$name.error_log
0N/A CustomLog /var/log/httpd/$name.access_log combined
0N/A&lt;/VirtualHost&gt;
0N/A&lt;/Macro&gt;</pre>
0N/A
0N/A
0N/A<p>Macro names are case-insensitive, like httpd configuration
0N/Adirectives. However, variable names are case sensitive.</p>
0N/A
0N/A<p>You would then invoke this macro several times to create virtual
0N/Ahosts:</p>
0N/A
0N/A<pre class="prettyprint lang-config">Use VHost example example.com
0N/AUse VHost myhost hostname.org
0N/AUse VHost apache apache.org
0N/A
0N/AUndefMacro VHost</pre>
0N/A
0N/A
0N/A<p>At server startup time, each of these <code class="directive">Use</code>
0N/Ainvocations would be expanded into a full virtualhost, as
0N/Adescribed by the <code class="directive">Macro</code> definition.</p>
0N/A
0N/A<p>The <code class="directive">UndefMacro</code> directive is used so that later
0N/Amacros using the same variable names don't result in conflicting
0N/Adefinitions.</p>
0N/A
0N/A<p>A more elaborate version of this example may be seen below in the
0N/AExamples section.</p>
0N/A
0N/A</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0N/A<div class="section">
0N/A<h2><a name="tips" id="tips">Tips</a></h2>
0N/A
0N/A<p>Parameter names should begin with a sigil such as <code>$</code>,
0N/A<code>%</code>, or <code>@</code>, so that they are clearly
0N/Aidentifiable, and also in order to help deal with interactions with
0N/Aother directives, such as the core <code class="directive"><a href="/mod/core.html#define">Define</a></code> directive. Failure to do so will
0N/Aresult in a warning. Nevertheless, you are encouraged to have a good
0N/Aknowledge of your entire server configuration in order to avoid reusing
0N/Athe same variables in different scopes, which can cause confusion.</p>
0N/A
0N/A<p>Parameters prefixed with either <code>$</code> or <code>%</code> are
0N/Anot escaped. Parameters prefixes with <code>@</code> are escaped in
0N/Aquotes.</p>
0N/A
0N/A<p>Avoid using a parameter which contains another parameter as a prefix,
0N/A(For example, <code>$win</code> and <code>$winter</code>) as this may
0N/Acause confusion at expression evaluation time. In the event of such
0N/Aconfusion, the longest possible parameter name is used.</p>
0N/A
0N/A<p>If you want to use a value within another string, it is useful to
0N/Asurround the parameter in braces, to avoid confusion:</p>
0N/A
0N/A<pre class="prettyprint lang-config">&lt;Macro DocRoot ${docroot}&gt;
0N/A DocumentRoot /var/www/${docroot}/htdocs
0N/A&lt;/Macro&gt;</pre>
0N/A
0N/A
0N/A</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0N/A<div class="section">
0N/A<h2><a name="examples" id="examples">Examples</a></h2>
0N/A
0N/A
0N/A<h3>Virtual Host Definition</h3>
0N/A
0N/A
0N/A<p>A common usage of <code class="module"><a href="/mod/mod_macro.html">mod_macro</a></code> is for the creation of
0N/Adynamically-generated virtual hosts.</p>
0N/A
0N/A<pre class="prettyprint lang-config">## Define a VHost Macro for repetitive configurations
0N/A
0N/A&lt;Macro VHost $host $port $dir&gt;
0N/A Listen $port
0N/A &lt;VirtualHost *:$port&gt;
0N/A
0N/A ServerName $host
0N/A DocumentRoot $dir
0N/A
0N/A # Public document root
0N/A &lt;Directory $dir&gt;
0N/A Require all granted
0N/A &lt;/Directory&gt;
0N/A
0N/A # limit access to intranet subdir.
0N/A &lt;Directory $dir/intranet&gt;
0N/A Require ip 10.0.0.0/8
0N/A &lt;/Directory&gt;
0N/A &lt;/VirtualHost&gt;
0N/A&lt;/Macro&gt;
0N/A
0N/A## Use of VHost with different arguments.
0N/A
0N/AUse VHost www.apache.org 80 /vhosts/apache/htdocs
0N/AUse VHost example.org 8080 /vhosts/example/htdocs
0N/AUse VHost www.example.fr 1234 /vhosts/example.fr/htdocs</pre>
0N/A
0N/A
0N/A
0N/A<h3>Removal of a macro definition</h3>
0N/A
0N/A
0N/A<p>It's recommended that you undefine a macro once you've used it. This
0N/Aavoids confusion in a complex configuration file where there may be
0N/Aconflicts in variable names.</p>
0N/A
0N/A<pre class="prettyprint lang-config">&lt;Macro DirGroup $dir $group&gt;
0N/A &lt;Directory $dir&gt;
0N/A Require group $group
0N/A &lt;/Directory&gt;
0N/A&lt;/Macro&gt;
0N/A
0N/AUse DirGroup /www/apache/private private
0N/AUse DirGroup /www/apache/server admin
0N/A
0N/AUndefMacro DirGroup</pre>
0N/A
0N/A
0N/A
0N/A
0N/A</div>
0N/A<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0N/A<div class="directive-section"><h2><a name="Macro" id="Macro">&lt;Macro&gt;</a> <a name="macro" id="macro">Directive</a></h2>
0N/A<table class="directive">
0N/A<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Define a configuration file macro</td></tr>
0N/A<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>
0N/A&lt;Macro <var>name</var> [<var>par1</var> .. <var>parN</var>]&gt;
0N/A... &lt;/Macro&gt;</code></td></tr>
0N/A<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
0N/A<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
0N/A<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_macro</td></tr>
0N/A</table>
0N/A <p>The <code class="directive">Macro</code> directive controls the definition of
0N/A a macro within the server runtime configuration files.
0N/A The first argument is the name of the macro.
0N/A Other arguments are parameters to the macro. It is good practice to prefix
0N/A parameter names with any of '<code>$%@</code>', and not macro names
0N/A with such characters.
0N/A </p>
0N/A
0N/A <pre class="prettyprint lang-config">&lt;Macro LocalAccessPolicy&gt;
0N/A Require ip 10.2.16.0/24
0N/A&lt;/Macro&gt;
0N/A
0N/A&lt;Macro RestrictedAccessPolicy $ipnumbers&gt;
0N/A Require ip $ipnumbers
0N/A&lt;/Macro&gt;</pre>
0N/A
0N/A
0N/A</div>
0N/A<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0N/A<div class="directive-section"><h2><a name="UndefMacro" id="UndefMacro">UndefMacro</a> <a name="undefmacro" id="undefmacro">Directive</a></h2>
0N/A<table class="directive">
0N/A<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Undefine a macro</td></tr>
0N/A<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>UndefMacro <var>name</var></code></td></tr>
0N/A<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
0N/A<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
0N/A<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_macro</td></tr>
0N/A</table>
0N/A <p>The <code class="directive">UndefMacro</code> directive undefines a macro
0N/A which has been defined before hand.</p>
0N/A
0N/A <pre class="prettyprint lang-config">UndefMacro LocalAccessPolicy
0N/AUndefMacro RestrictedAccessPolicy</pre>
0N/A
0N/A
0N/A</div>
0N/A<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
0N/A<div class="directive-section"><h2><a name="Use" id="Use">Use</a> <a name="use" id="use">Directive</a></h2>
0N/A<table class="directive">
0N/A<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Use a macro</td></tr>
0N/A<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>Use <var>name</var> [<var>value1</var> ... <var>valueN</var>]
0N/A</code></td></tr>
0N/A<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory</td></tr>
0N/A<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
0N/A<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_macro</td></tr>
0N/A</table>
0N/A <p>The <code class="directive">Use</code> directive controls the use of a macro.
0N/A The specified macro is expanded. It must be given the same number of
0N/A arguments as in the macro definition. The provided values are
0N/A associated to their corresponding initial parameters and are substituted
0N/A before processing.</p>
0N/A
0N/A <pre class="prettyprint lang-config">Use LocalAccessPolicy
0N/A...
0N/AUse RestrictedAccessPolicy "192.54.172.0/24 192.54.148.0/24"</pre>
0N/A
0N/A
0N/A <p>is equivalent, with the macros defined above, to:</p>
0N/A
0N/A <pre class="prettyprint lang-config">Require ip 10.2.16.0/24
0N/A...
0N/ARequire ip 192.54.172.0/24 192.54.148.0/24</pre>
0N/A
0N/A
0N/A</div>
0N/A</div>
0N/A<div class="bottomlang">
0N/A<p><span>Available Languages: </span><a href="/en/mod/mod_macro.html" title="English">&nbsp;en&nbsp;</a> |
0N/A<a href="/fr/mod/mod_macro.html" hreflang="fr" rel="alternate" title="Fran�ais">&nbsp;fr&nbsp;</a></p>
0N/A</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>
0N/A<script type="text/javascript"><!--//--><![CDATA[//><!--
0N/Avar comments_shortname = 'httpd';
0N/Avar comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_macro.html';
0N/A(function(w, d) {
0N/A if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
0N/A d.write('<div id="comments_thread"><\/div>');
0N/A var s = d.createElement('script');
0N/A s.type = 'text/javascript';
0N/A s.async = true;
0N/A s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
0N/A (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
0N/A }
0N/A else {
0N/A d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
0N/A }
0N/A})(window, document);
0N/A//--><!]]></script></div><div id="footer">
0N/A<p class="apache">Copyright 2015 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>
0N/A<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[//><!--
0N/Aif (typeof(prettyPrint) !== 'undefined') {
0N/A prettyPrint();
0N/A}
0N/A//--><!]]></script>
0N/A</body></html>