Apache The Definitive Guide, 3rd EditionApache: The Definitive GuideSearch this book

16.5. Script Directives

Apache has five directives dealing with CGI scripts.

ScriptAlias

ScriptAlias URLpath CGIpath
Server config, virtual host

The ScriptAlias directive does two things. It sets Apache up to execute CGI scripts, and it converts requests for URLs starting with URLpathto execution of the script in CGIpath. For example:

ScriptAlias /bin /usr/local/apache/cgi-bin

An incoming URL like www.butterthlies.com/bin/fred will run the script /usr/local/apache/cgi-bin/fred. Note that CGIpath must be an absolute path, starting at /.

A very useful feature of ScriptAlias is that the incoming URL can be loaded with fake subdirectories. Thus, the incoming URL www.butterthlies.com/bin/fred/purchase/learjetwill run .../fred as before, but will also make the text purchase/learjet available to fred in the environment variable PATH_INFO. In this way you can write a single script to handle a multitude of different requests. You just need to monitor the command-line arguments at the top and dispatch the requests to different subroutines.

ScriptAliasMatch

ScriptAliasMatch regex directory
Server config, virtual host

This directive is equivalent to ScriptAlias but makes use of standard regular expressions instead of simple prefix matching. The supplied regular expression is matched against the URL; if it matches, the server will substitute any parenthesized matches into the given string and use the result as a filename. For example, to activate any script in /cgi-bin, one might use the following:

ScriptAliasMatch /cgi-bin/(.*) /usr/local/apache/cgi-bin/$1

If the user is sent by a link to http://www.butterthlies.com/cgi-bin/script3, "/cgi-bin/"matches against /cgi-bin/. We then have to match script3 against .*, which works, because "." means any character and "*" means any number of whatever matches ".". The parentheses around .* tell Apache to store whatever matched to .* in the variable $1. (If some other pattern followed, also surrounded by parentheses, that would be stored in $2). In the second part of the line, ScriptAliasMatch is told, in effect, to run /usr/local/apache/cgi-bin/script3.

ScriptLog

ScriptLog filename
Default: no logging
Resource config

Since debugging CGI scripts can be rather opaque, this directive allows you to choose a log file that shows what is happening with CGIs. However, once the scripts are working, disable logging, since it slows Apache down and offers the Bad Guys some tempting crannies.

ScriptLogLength

ScriptLogLength number_of_bytes
Default number_of_bytes: 10385760[60]
Resource config

This directive specifies the maximum length of the debug log. Once this value is exceeded, logging stops (after the last complete message).

[60] This curious number is almost certainly a typo in the source: 10 MB is 10485760 bytes.

ScriptLogBuffer

ScriptLogBuffer number_of_bytes
Default number_of_bytes: 1024
Resource config

This directive specifies the maximum size in bytes for recording a POST request.

Figure

Scripts can go wild and monopolize system resources: this unhappy outcome can be controlled by three directives.

RLimitMEM

RLimitMEM # | 'max' [# | 'max']
Default: OS defaults
Server config, virtual host

Figure

RLimitMEM takes one or two parameters. Each parameter may be a number or the word max,which invokes the system maximum, in bytes of memory used per process. The first parameter sets the soft resource limit; the second the hard limit.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.