These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX02/Apache Configuration

Classnotes | UNIX02 | RecentChanges | Preferences

Difference (from prior major revision) (no other diffs)

Added: 100a101,103
#<IfModule? mod_userdir.c>
# UserDir? public_html
#</IfModule?>

Changed: 164c167
:See also http://httpd.apache.org/docs/configuring.html
:See also http://httpd.apache.org/docs/configuring.html

Apache's configuration file format contains markup similar to HTML or XML. This makes this file fairly easy to visualize and understand.

On Red Hat (and many other UNIX systems) Apache's configuration files are installed in /etc/httpd/conf. However, when built from source, Apache's configuration files have traditionally defaulted to /var/apache/conf. The move to /etc/httpd is a logical one, as most system configuration files go there, but you should be aware of the variants.

The basic configuration unit of the Apache config file is known as a Directive. There is allowed one Directive per line. Groups of Directives are broken up into Modules.

Taking a look at an example module from /etc/httpd/conf/httpd.conf:

 <Directory />
    Options FollowSymLinks?
    AllowOverride? None
 </Directory?>

We see that it is quite similar to various markup languages.

httpd.conf

Global Environment Settings

Most settings in this section of the configuration file are well documented. However, there are a few which we should examine more carefully.

 #
 # ServerType? is either inetd, or standalone.
 # Inetd mode is only supported on
 # Unix platforms.
 #
 ServerType? standalone

 #
 # ServerRoot?: The top of the directory tree under which the server's
 # configuration, error, and log files are kept.
 # Do NOT add a slash at the end of the directory path.
 #
 ServerRoot? "/etc/httpd"

 #
 # Number of servers to start initially --- should be a reasonable ballpark
 # figure.
 #
 StartServers? 8

 #
 # Limit on total number of servers running, i.e., limit on the number
 # of clients who can simultaneously connect --- if this limit is ever
 # reached, clients will be LOCKED OUT, so it should NOT BE SET TOO LOW.
 # It is intended mainly as a brake to keep a runaway server from taking
 # the system with it as it spirals down...
 #
 MaxClients? 150

 #
 # MaxRequestsPerChild?: the number of requests each child process is
 # allowed to process before the child dies.  The child will exit so
 # as to avoid problems after prolonged use when Apache (and maybe the
 # libraries it uses) leak memory or other resources.  On most systems, this
 # isn't really needed, but a few (such as Solaris) do have notable leaks
 # in the libraries. For these platforms, set to something like 10000
 # or so; a setting of 0 means unlimited.
 #
 # NOTE: This value does not include keepalive requests after the initial
 #       request per connection. For example, if a child process handles
 #       an initial request and 10 subsequent "keptalive" requests, it
 #       would only count as 1 request towards this limit.
 #
 MaxRequestsPerChild? 1000

Main Server Configuration

This next section is the one which you will spend most of your time on.

 #
 # Port: The port to which the standalone server listens. For
 # ports < 1023, you will need httpd to be run as root initially.
 #
 Port 80

 #
 # DocumentRoot?: The directory out of which you will serve your
 # documents. By default, all requests are taken from this directory, but
 # symbolic links and aliases may be used to point to other locations.
 #
 DocumentRoot? "/var/www/html"

 #
 # Each directory to which Apache has access, can be configured with
 # respect
 # to which services and features are allowed and/or disabled in that
 # directory (and its subdirectories).
 #
 # First, we configure the "default" to be a very restrictive set of
 # permissions.
 #
 <Directory />
    Options FollowSymLinks?
    AllowOverride? None
 </Directory?>

For more information on Options, see this page: http://httpd.apache.org/docs/mod/core.html#options

For more information on AllowOverride?, see this: http://httpd.apache.org/docs/mod/core.html#allowoverride

For documentation on all the directives see this: http://httpd.apache.org/docs/mod/directives.html

 #<IfModule? mod_userdir.c>
 #    UserDir? public_html
 #</IfModule?>
 #
 # Control access to UserDir? directories.  The following is an example
 # for a site where these directories are restricted to read-only.
 #
 #<Directory /home/*/public_html>
 #    AllowOverride? FileInfo? AuthConfig? Limit
 #    Options MultiViews? Indexes SymLinksIfOwnerMatch? IncludesNoExec?
 #    <Limit GET POST OPTIONS PROPFIND>
 #        Order allow,deny
 #        Allow from all
 #    </Limit?>
 #    <LimitExcept? GET POST OPTIONS PROPFIND>
 #        Order deny,allow
 #        Deny from all
 #    </LimitExcept?>
 #</Directory?>

Aliasing

For many reasons (including security) you wont want to let those browsing to your web-site know the internal structure and layout of your web-site. For this reason, Apache has a module dedicated to aliasing directories.

Aliased directories give you a great deal of freedom as a system administrator as where Apache will get its content, but too many aliases in too many diverse locations can make system maintenance more difficult. Thus, it is ultimately up to you to use your best judgement as to how many and where you place your aliases.

The aliases section of httpd.conf begins with

 <IfModule? mod_alias.c>

and each alias should have the following basic cluster of information:

    Alias /directory/ "/path/to/some/directory/"

    <Directory "/path/to/some/directory">
        Options Indexes MultiViews?
        AllowOverride? None
        Order allow,deny
        Allow from all
    </Directory?>

Often you will want to have a script directory where system-wide server side scripts go. Most of the time, the default for this is as follows:

    ScriptAlias? /cgi-bin/ "/var/www/cgi-bin/"

    <Directory "/var/www/cgi-bin">
        AllowOverride? None
        Options None
        Order allow,deny
        Allow from all
    </Directory?>

Note that if you want to allow CGI scripting outside of the system-wide cgi-bin directory, you will want to use AddHandler?:

 #
 # AddHandler? allows you to map certain file extensions to "handlers",
 # actions unrelated to filetype. These can be either built into the server
 # or added with the Action command (see below)
 #
 # If you want to use server side includes, or CGI outside
 # ScriptAliased? directories, uncomment the following lines.
 #
 # To use CGI scripts:
 #
 #AddHandler? cgi-script .cgi

srm.conf and access.conf

These two files are not generally used on Red Hat systems. All of the directives that go into these files can also be added to the httpd.conf file, and thus, they are rarely used themselves. Even if you are not using Red Hat, you do not have to use these files, as their information can always be placed in httpd.conf.

For more information see: http://www.redhat.com/support/resources/faqs/RH-apache-FAQ/book1.html

See also http://httpd.apache.org/docs/configuring.html


Classnotes | UNIX02 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited April 26, 2003 9:19 pm (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.