From: Luca Toscano Date: Tue, 16 Feb 2016 18:42:26 +0000 (+0000) Subject: New proposal for the sections.html documentation. X-Git-Tag: 2.5.0-alpha~2058 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c140907ebf34e14a9c841e5176c2b7ca097669e;p=thirdparty%2Fapache%2Fhttpd.git New proposal for the sections.html documentation. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1730730 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/docs/manual/sections.xml b/docs/manual/sections.xml index e77961c18f5..cee3d5c0b55 100644 --- a/docs/manual/sections.xml +++ b/docs/manual/sections.xml @@ -510,19 +510,7 @@ are interpreted, it is important to understand how this works.

type="section">Directory container in the processing order.

-Merge is not always Override -

Later sections override earlier ones, however each module is responsible - for interpreting what form this override takes. A later configuration section - with directives from a given module might cause a conceptual "merge" of some - directives, all directives, or a complete replacement of the modules - configuration with the module defaults and directives explicitly listed in - the later context.

-

Directory, FilesMatch, - Location and the other directives discussed in this section - implement the same merging strategy, namely "override" when applied to the same target.

-
- -Technical Note + Technical Note There is actually a <Location>/<LocationMatch> sequence performed just before the name translation phase @@ -530,9 +518,54 @@ are interpreted, it is important to understand how this works.

are used to map URLs to filenames). The results of this sequence are completely thrown away after the translation has completed. -
+
+ +
Relationship between modules and configuration sections +

One question that often arises after reading how configuration sections are + merged is related to how and when directives of specific modules like mod_rewrite + are processed. The answer is not trivial and needs a bit of background. + Each httpd module manages its own configuration, and each of its directives in httpd.conf specify one piece + of configuration in a particular context. httpd does not execute a command as it is read.

+

At runtime, the core of httpd iterates over the defined configuration sections in the order + described above to determine which ones apply to the current request. When the first section matches, + it is considered the current configuration for this request. If a subsequent section matches too, + then each module with a directive in either of the sections is given a chance to merge its configuration between the two sections. The result is a third configuration, and the process goes on until all the configuration sections + are evaluated.

+

After the above step, the "real" processing of the HTTP request begins: each module has a chance to run + and perform whatever tasks they like. They can retrieve their own final merged configuration from the core + of the httpd to determine how they should act.

+

An example can help to visualize the whole process. The following configuration uses the + Header directive of mod_headers to set + a specific HTTP header. What value will httpd set in the foo header for a request to + /example/index.html ? +

+ -
Some Examples +<Directory "/"> + Header set foo one + <FilesMatch ".*"> + Header set foo three + </FilesMatch> +</Directory> + +<Directory "/example"> + Header set foo two +</Directory> + + +
    +
  • Directory "/" matches and an initial configuration to set the "foo" header with the value "one" is created.
  • +
  • Directory "/example" matches, and since mod_headers specifies in its code to override in case of a merge, a new configuration is created to set the "foo" header with the value "two".
  • +
  • FilesMatch ".*" matches and another merge opportunity arises, causing the "foo" header + to be set with the value "three".
  • +
  • Eventually during the next steps of the HTTP request processing mod_headers will be called and it will receive the configuration to set the "foo" header with the value "three". mod_headers normally uses this configuration to perfom its job, namely setting the foo header. This does not mean that a module can't perform a more complex action like discarding directives because not needed or deprecated, etc..
  • +
+ +

This is true for .htaccess too since they have the same priority as Directory in the merge order. The important concept to understand is that configuration sections like Directory and FilesMatch are not comparable to module specific directives like Header or RewriteRule because they operate on different levels. +

+
+ +
Some useful merge examples to practice

Below is an artificial example to show the order of merging. Assuming they all apply to the request, the directives in @@ -564,34 +597,6 @@ E.

-

Another interesting example is the following one. As described above, -FilesMatch is merged after Directory, -therefore a request for /var/www/index.html will eventually get the "foo" Header set to -the value "two", not "three" as somebody might expect from a first look. -

- - -<Directory "/"> - Header set foo one - <FilesMatch ".*"> - Header set foo two - </FilesMatch> -</Directory> - -<Directory "/var/www"> - Header set foo three -</Directory> - - - -

The chain of values that the "foo" header will get is: "one", "three" and "two". -It is important to notice that Directory and FilesMatch -implement the same merging strategy, namely "override" when -applied to the same path. In this example it means that the last directive applied in the merging order, -FilesMatch, sets the final value for the "foo" header. -

-

This is true for .htaccess too, since they have the same priority as Directory -in the merging order.

For a more concrete example, consider the following. Regardless of any access restrictions placed in