The Main Server section covers directives used to manage the operation of the primary web site to which the Apache web server is host. In addition the values used for the directives set in the main server section are used as the default values for any configuration done within the Virtual Host section.
The most commonly used configuration options within the Main Server and Virtual Host section are containers that operate on the configuration of particular resources in the filesystem or webspace.
■ Filesystem: The view of the resources as seen by the operating system. For example, on SUSE Linux, the web pages for Apache to serve reside at /srv/www on the filesystem.
■ Webspace: The view of the resources as seen by the web server and by the client. For example, the path /dir/ in the webspace might correspond to the path /srv/www/htdocs/dir/ in the filesystem. Of course, the webspace need not map directly to the filesystem because web pages may be generated dynamically from databases or other locations.
The <Directory> and <Files> containers, however, are batches of directives that apply to resources as seen from the filesystem. Directives enclosed in a <Directory> container apply to the named filesystem directory and all subdirectories therein. For example, in the following configuration, directory indexes will be enabled for the /srv/www/htdocs/dir directory and all subdirectories:
<Directory /srv/www/htdocs/dir> Options +Indexes </Directory>
Directives enclosed in the <Files> container apply to any file with the specified name, regardless of what directory it resides in. For example, the following configuration directives deny access to any file named private.html regardless of where it is found:
<Files private.html> Order allow.deny Deny from all </Files>
If, however, a directive needs to focus on a file found in a particular part of the filesystem, the <Files> and <Directory> containers can be nested, allowing for granular control of resources within the configuration file.
Deny from all
In the preceding example, the configuration will deny access to /srv/www/htdocs/dir /private.html and any files named private.html within any subdirectories found within /srv/www/htdocs/dir/.
In the area of webspace, the <Location> directive operates on the configuration of resources found from within this point of view. The following configuration example prevents access to any URL-path that begins with the string /private, such as <http://www.suse.com /private>:
<Location /private> Order Allow.Deny Deny from all </Location>
Unlike the <Directory> or <Files> containers, the <Location> directive need not have anything to do with a resource located on the filesystem. This is useful for dynamically generated content that has no physical location on the filesystem. An example can be seen with the Apache module mod_status, which provides dynamic information about the running Apache processes. The dynamic information is mapped to a particular URL, usually /server-status. Because no file exists at a corresponding filesystem location, any directives, just as the Order and Deny directive previously mentioned, must be contained within the <Location> container:
<Location /server-status> Order Allow.Deny Deny from all </Location>
Why all the fuss about containers representing resources from the point of view of the filesystem or webspace? Generally, directives placed in the main configuration file apply to the entire site. Thus, to manage the configuration for only a section or specific resource contained within a site the directive containers such as <Directory>, <Files>, and <Location> are necessary.
Was this article helpful?