Publishing Content


DocumentRoot /usr/local/apache/htdocs


By default, Apache serves content from the htdocs/ directory (which historically stands for HTML documents) in the installation directory. You can place documents there and they will automatically appear in the URL space of the document. For example, if you create a directory inside htdocs named foo and place the file bar.html inside it, it will be accessible from the outside as

http://www.example.com/foo/bar.html


You can change the location for the documents directory with the DocumentRoot directive, as shown. If a relative path is specified then it will be considered relative to the path specified by the ServerRoot directive.

You don't necessarily need to place your content under the document root directory. One of the strengths of Apache is that it provides a number of powerful and flexible mechanisms for mapping URLs requested by clients into files on disks or resources provided by modules. Please see Chapter 4 for details.

Directive Containers

Directive containers, also called sections, limit the scope to which directives apply. If directives are not inside a container, they belong to the default server scope (server config), applying to the server as a whole.

<Directory "/usr/local/apache/htdocs"> ... </Directory> <Location "/downloads/*.html"> ... </Location> <FilesMatch "\.(gif|jpg)"> ... </FilesMatch>


Default Apache Directive Containers

The following directive containers are the default containers used in Apache configuration files.

<VirtualHost> A VirtualHost directive specifies a virtual server. Apache enables you to host different websites with a single Apache installation, as described in Chapter 5.

<Directory> and <DirectoryMatch> These containers apply directives to a certain directory or group of directories in the file system. The DirectoryMatch container allows regular expression patterns to be used as arguments.

<Location> and <LocationMatch> Applies directives to certain requested URLs or URL patterns. They are similar to Directory containers.

<Files> and <FilesMatch> Similar to Directory and Location containers, Files sections apply directives to certain files or file patterns.

These are not the only directive containers available. Modules, such as mod_proxy, may provide their own containers, as explained in Chapter 10. See also Chapter 8 for details on containers that limit access based on HTTP methods.

Note

Directory, Files, and Location sections can also take regular expression arguments by preceding them with a ~. Regular expressions are strings that describe or match a set of strings, according to certain syntax rules. For example, the following regular expression will match all requests asking for an image file with a .jpg or .gif extension: <Files ~ "\.(gif|jpg)">. However, the DirectoryMatch, LocationMatch, and FilesMatch directives are preferred for clarity. You can learn more about regular expressions at http://en.wikipedia.org/wiki/Regular_expression.


Directive Containers for Conditional Evaluation

Apache provides support for conditional containers. Directives enclosed in these containers will be processed only if certain conditions are met.

<IfDefine> Directives in this container will be processed if a specific command-line switch is passed to the Apache executable. In the following example, the command-line switch should be DSSL. Similarly, you can negate the argument with a "!", as in <IfDefine !SSL>, if you want the directives to apply if the switch was not passed.

<IfModule> Directives in an IfModule section will be processed only if the module passed as an argument is present in the web server. The default Apache configuration file includes such examples for different MPMs modules.

For example, in the httpd.conf file, you would see

<IfDefine SSL> LoadModule ssl_module modules/mod_ssl.so </IfDefine>


And you would enable it at the command line like this:

# httpd -DSSL






Apache(c) Phrase Book(c) Essential Code and Commands
Apache Phrasebook
ISBN: 0672328364
EAN: 2147483647
Year: 2006
Pages: 254

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net