Show Contents Previous Page Next Page Chapter 8 - Customizing the Apache Configuration Process / The Apache Configuration Directive API
In addition to specifying the syntax of your custom configuration directives, you can establish limits on how they can be used by specifying the
The value of 'req_override' => 'RSRC_CONF | ACCESS_CONF'
As in the case of Directive Definition Shortcuts Show Contents Go to Top Previous Page Next Page
We've already seen how to simplify your configuration directives by allowing command_table() to deduce the correct
If you pass command_table() a list of array references rather than hash references, then it will take the first item in each array ref to be the name of the configuration directive, and the second item to be the error/usage message. By taking advantage of this shortcut, we can rewrite the list of configuration directives at the beginning of this section more succinctly: @directives = ( [ 'TrafficCopSpeedLimit', 'an integer specifying the maximum allowable bytes per second', ], [ 'TrafficCopRightOfWay', 'list of domains that can go as fast as they want', ], ); command_table(\@directives); You can also mix and match the two configuration styles. The Configuration Creation and Merging Show Contents Go to Top Previous Page Next PageDigging deeper, the process of module configuration is more complex than you'd expect because Apache recognizes multiple levels of configuration directives. There are global directives contained within the main httpd.conf file, per-server directives specific to virtual hosts contained within <VirtualHost> sections, and per-directory configuration directives contained within <Directory> sections and .htaccess files. To understand why this issue is important, consider this series of directives: TrafficCopSpeedLimit 55 <Location /I-95> TrafficCopRightOfWay .mil .gov TrafficCopSpeedLimit 65 </Location> <Location /I-95/exit-13> TrafficCopSpeedLimit 30 </Location> When processing URLs in /I-95/exit13, there's a potential source of conflict because the TrafficCopSpeedLimit directive appears in several places. Intuitively, the more specific directive should take precedence over the one in its parent directory, but what about TrafficCopRightOfWay? Should /I-95/exit13 inherit the value of TrafficCopRightOfWay or ignore it? On top of this, there is the issue of per-server and per-directory configuration information. Some directives, such as HostName, clearly apply to the server as a whole and have no reason to change on a per-directory basis. Other directives, such as Options, apply to individual directories or URIs. Per-server and per-directory configuration information should be handled separately from each other. To handle these issues, modules may declare as many as four subroutines to set configuration policy: SERVER_CREATE(), DIR_CREATE(), SERVER_MERGE(), and DIR_MERGE(). The SERVER_CREATE() and DIR_CREATE() routines are responsible for creating per-server and per-directory configuration objects. If present, they are invoked before Apache has processed any of the module's configuration directives in order to create a default per-server or per-directory configuration. Provided that at least one of the module's configuration directives appears in the main part of the configuration file, SERVER_CREATE() will be called once for the main server host and once for each virtual host. Similarly, DIR_CREATE() will be called once for each directory section (including <Location> and .htaccess files) in which at least one of the module's configuration directives appears.
As Apache parses and processes the module's custom directives, it invokes the directive callbacks to add information to the per-server and per-directory configuration records. Since the vast majority of modules act at a per-directory level, Apache passes the per-directory configuration object to the callbacks as the first argument. This is the Later in the configuration process, one or both of the SERVER_MERGE() and DIR_MERGE() subroutines may be called. These routines are responsible for merging a parent per-server or per-directory configuration record with a configuration that is lower in the hierarchy. For example, merging will be required when one or more of a module's configuration directives appear in both a <Location /images> section and a <Location /images/PNG> section. In this case, DIR_CREATE() will be called to create default configuration records for each of the /images and /images/PNG directories, and the configuration directives' callbacks will be called to set up the appropriate fields in these newly created configurations. After this, the DIR_MERGE() subroutine is called once to merge the two configuration objects together. The merged configuration now becomes the per-directory configuration for /images/PNG. This merging process is repeated as many times as needed. If a directory or virtual host section contains none of a particular module's configuration directives, then the configuration handlers are skipped and the configuration for the closest ancestor of the directory is used instead. In addition to being called at server startup time, the DIR_CREATE() function may be invoked again at request time, for example, whenever Apache processes a .htaccess file. The DIR_MERGE() functions are always invoked at request time in order to merge the current directory's configuration with its parents.
When C modules implement configuration directive handlers they must, at the very least, define a per-directory or per-server constructor for their configuration data. However, if a Perl module does not implement a constructor, Neither C nor Perl modules are required to implement merging routines. If they do not, merging simply does not happen and Apache uses the most specific configuration record. In the example at the top of this section, the configuration record for the URI location /I-95/exit-13 would contain the current value of TrafficCop-SpeedLimit but no specific value for TrafficCopRightOfWay. Depending on your module's configuration system, you may wish to implement one or more of the configuration creation and merging methods described in the following list. The method names use the all-uppercase naming convention because they are never called by any other user code.
The SERVER_CREATE() and SERVER_MERGE() methods work just like DIR_ CREATE() and DIR_MERGE(). The difference is simply in the scope and timing in which they are created and merged. The SERVER_CREATE() method is only called once per configured virtual server. The SERVER_MERGE() method is invoked during server startup time, rather than at request time like DIR_MERGE(). Copyright © 1999 by O'Reilly & Associates, Inc. |
HIVE: All information for read only. Please respect copyright! |