Book HomeApache: The Definitive GuideSearch this book

4.3. Script Directives

Apache has five directives defining CGI script alternatives.

4.3.1. ScriptAlias

ScriptAlias URLpath directory
Server config, virtual host

The ScriptAlias directive converts requests for URLs starting with URLpath to execution of the CGI program found in directory. In other words, an incoming URL like URLpath/fred causes the program stored in directory/fred to run, and its output is returned to the client. Note that directory must be an absolute path. We recommend that this path be outside your webspace.

A cute feature of ScriptAlias is that it can allow a CGI to pretend to be a directory. If someone submits the URL URLpath/fred/some/where/else, then directory/fred is run, and /some/where/else is passed to it in the PATH_INFO environment variable. This can be used for all sorts of things, but one is worth mentioning: many browsers and caches detect CGIs by the presence of a question mark in the URL, and refuse to cache them. This gives a way of fooling them into caching. Of course, you should be sure you want them cached (or use cache control headers to prevent it, if that was not what you had in mind).

4.3.2. 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 the standard /cgi-bin, one might use the following:

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

4.3.3. 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.

4.3.4. ScriptLogLength

ScriptLogLength number_of_bytes
Default number_of_bytes: 10385760[35]
Resource config

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

4.3.5. 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 4.3.5 Scripts can go wild and monopolize system resources: this unhappy outcome can be controlled by three directives.

4.3.6. RLimitCPU

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

Figure 4.3.6 RLimitCPU takes one or two parameters. Each parameter may be a number or the word max, which invokes the system maximum, in seconds per process. The first parameter sets the soft resource limit, the second the hard limit.[36]

[36]The soft limit can be increased again by the child process, but the hard limit cannot. This allows you to set a default that is lower than the highest you are prepared to allow. See man rlimit for more detail.

4.3.7. RLimitMEM


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

Figure 4.3.7 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.

4.3.8. RLimitNPROC

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

Figure 4.3.8 RLimitNPROC takes one or two parameters. Each parameter may be a number or the word max, which invokes the system maximum, in processes per user. The first parameter sets the soft resource limit, the second the hard limit.



Library Navigation Links

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