From e546b9d131b8b5ac3445a1f2c49a1bdcf819aa4d Mon Sep 17 00:00:00 2001 From: Rich Bowen Date: Mon, 23 Sep 2013 00:17:51 +0000 Subject: [PATCH] Merges doc restructure from trunk. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1525476 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/mod/mod_macro.xml | 208 ++++++++++++++++++++++++---------- 1 file changed, 145 insertions(+), 63 deletions(-) diff --git a/docs/manual/mod/mod_macro.xml b/docs/manual/mod/mod_macro.xml index 501977087b..efd06445d2 100644 --- a/docs/manual/mod/mod_macro.xml +++ b/docs/manual/mod/mod_macro.xml @@ -23,76 +23,153 @@ mod_macro -This module provides usage of macros within apache runtime configuration files +Provides macros within apache httpd runtime configuration files Base mod_macro.c macro_module -Available in Apache HTTPD 2.4.5 and later -

This module provides macros within apache runtime configuration files. - These macros have parameters. They are expanded when used (parameters are - substituted by their values given as an argument), and the result is - processed normally.

+

Provides macros within Apache httpd runtime configuration files, + to ease the process of creating numerous similar configuration + blocks. When the server starts up, the macros are expanded using the + provided parameters, and the result is processed as along with the + rest of the configuration file.

+
-
Features - -

Definition of a macro:

-
    -
  • macro definition within a <Macro> section, following - the apache style.
  • -
  • user defined names for the macro and its parameters.
  • -
  • macro names are case-insensitive, like apache directives.
  • -
  • macro parameter names are case sensitive.
  • -
  • macro parameters must have distinct names.
  • -
  • error on empty parameter names.
  • -
  • redefining a macro generates a warning.
  • -
  • macro definitions can be nested... (but what for?)
  • -
  • warn about unused macro parameters.
  • -
  • warn about macro parameter names which prefix one another.
  • -
  • warn if a parameter is not prefixed by any of '$%@' - (good practice).
  • -
  • the available prefixes help deal with interactions with other - directives such as Define.
  • -
  • tip: it may be useful to define a macro parameter with surrounding - braces, say ${foo} so that the name can appear with - surrounding characters such as bla${foo}bla.
  • -
  • warn about empty macro contents.
  • -
  • warns if sections are not properly nested within a macro. - (if it is detected so).
  • -
  • the lexical scope of macro parameters is restricted to the macro text, - it is not forwarded to includes for instance.
  • -
  • arbitrary contents in macros. -

    It means you can put perl sections or whatever you like in a macro. - No assumption is made about the lexical structure (quotes, spaces or - whatever) within the macro contents but to expect a set of - backslash-continued independent lines.

  • -
- -

Use of a macro:

-
    -
  • number of arguments must match the definition.
  • -
  • all occurences of macro parameters are substituted by their values.
  • -
  • in case of conflicts, the longest parameter name is chosen.
  • -
  • macro expansion recursion is detected and stopped (error).
  • -
  • warn about empty arguments when used.
  • -
  • on errors, try to describe precisely where the error occured.
  • -
  • $ and %-prefixed parameters are not - escaped.
  • -
  • @-prefixed parameters are escaped in quotes.
  • -
- -

Removal of a macro definition:

-
    -
  • the macro must be already defined.
  • -
+
Usage - +

Macros are defined using Macro blocks, which contain the portion of +your configuration that needs to be repeated, complete with variables +for those parts that will need to be substituted.

+ +

For example, you might use a macro to define a VirtualHost block, in order to define +multiple similar virtual hosts:

+ + +<Macro VHost $name $domain> +<VirtualHost *:80> + ServerName $domain + ServerAlias www.$domain + + DocumentRoot /var/www/vhosts/$name + ErrorLog /var/log/httpd/$name.error_log + CustomLog /var/log/httpd/name.access_log combined +>/VirtualHost> +</Macro> + + +

Macro names are case-insensitive, like httpd configuration +directives. However, variable names are case sensitive.

+ +

You would then invoke this macro several times to create virtual +hosts:

+ + +Use VHost example example.com +Use VHost myhost hostname.org +Use VHost apache apache.org + +UndefMacro VHost + + +

At server startup time, each of these Use +invocations would be expanded into a full virtualhost, as +described by the Macro definition.

+ +

The UndefMacro directive is used so that later +macros using the same variable names don't result in conflicting +definitions.

+ +

A more elaborate version of this example may be seen below in the +Examples section.

+ +
+ +
Tips + +

Parameter names should begin with a sigil such as $, +%, or @, so that they are clearly +identifiable, and also in order to help deail with interactions with +other directives, such as the core Define directive. Failure to do so will +result in a warning. Nevertheless, you are encouraged to have a good +knowledge of your entire server configuration in order to avoid reusing +the same variables in different scopes, which can cause confusion.

+ +

Parameters prefixed with either $ or % are +not escaped. Parameters prefixes with @ are escaped in +quotes.

+ +

Avoid using a parameter which contains another parameter as a prefix, +(For example, $win and $winter) as this may +cause confusion at expression evaluation time. In the event of such +confusion, the longest possible parameter name is used.

+ +

If you want to use a value within another string, it is useful to +surround the parameter in braces, to avoid confusion:

+ + +<Macro DocRoot ${docroot}> + DocumentRoot /var/www/${docroot}/htdocs +</Macro> + + +
+ +
+Examples + +
+Virtual Host Definition + +

A common usage of mod_macro is for the creation of +dynamically-generated virtual hosts.

+ + +## Define a VHost Macro for repetitive configurations + +<Macro VHost $host $port $dir> + Listen $port + <VirtualHost *:$port> + + ServerName $host + DocumentRoot $dir + + # Public document root + <Directory $dir> + Require all granted + </Directory> + + # limit access to intranet subdir. + <Directory $dir/intranet> + Require ip 10.0.0.0/8 + </Directory> + </VirtualHost> +</Macro> + +## Use of VHost with different arguments. + +Use VHost www.apache.org 80 /vhosts/apache/htdocs +Use VHost example.org 8080 /vhosts/example/htdocs +Use VHost www.example.fr 1234 /vhosts/example.fr/htdocs + +
+ +
+Removal of a macro definition + +

It's recommended that you undefine a macro once you've used it. This +avoids confusion in a complex configuration file where there may be +conflicts in variable names.

+ + <Macro DirGroup $dir $group> <Directory $dir> - require group $group + Require group $group </Directory> </Macro> @@ -100,8 +177,11 @@ Use DirGroup /www/apache/private private Use DirGroup /www/apache/server admin UndefMacro DirGroup - -
+ + +
+ +
@@ -150,7 +230,7 @@ UndefMacro DirGroup -

The Use directive controls the use of a macro. +

The Use directive controls the use of a macro. The specified macro is expanded. It must be given the same number of arguments than in the macro definition. The provided values are associated to their corresponding initial parameters and are substituted @@ -170,11 +250,12 @@ Require ip 10.2.16.0/24 Require ip 192.54.172.0/24 192.54.148.0/24 + -undefMacro +UndefMacro Undefine a macro UndefMacro name @@ -194,4 +275,5 @@ UndefMacro RestrictedAccessPolicy + -- 2.40.0