CGI Configuration


Back

Esehttpd and CGI

Esehttpd supports CGI in two forms. The normal method for executing a CGI script is to execute it as an external process. The other method is to execute a CGI script in the same process of esehttpd. The former is much faster, but can be used only for CGI scripts written in Ruby.

Settings for CGI scripts

To execute CGI scripts as external processes, add the following line to the configuration file.
  ScriptAlias /cgi-bin/ /usr/local/lib/esehttpd/www/cgi-bin/
This example maps the URIs beginning with '/cgi-bin/' to the directory '/usr/local/lib/esehttpd/www/cgi-bin/', and indicate that all the files in the directory shall be treat as CGI scripts and executed. CGI scripts must be able to be executed by the user specified by the User directive in the configuration file.

The cgi-ruby module

To execute CGI scripts written in ruby inside the same process of esehttpd, add the following line to the configuration file.
  ScriptAlias /cgi-ruby/ /usr/local/lib/esehttpd/www/cgi-ruby/ cgi-ruby
This example maps the URIs beginning with '/cgi-ruby/' to the directory '/usr/local/lib/esehttpd/www/cgi-bin/', and indicate that all the files in the directory shall be treat as CGI scripts and executed by the cgi-ruby module.

While a ruby script is evaluated, the esehttpd process can't do anything except for evaluating the ruby script. That is, the process blocks until the script is finished. If you want to use a CGI script which consumes a long time, using cgi-ruby module is not suitable.

When a ruby script is finished, all the global variables and constants remains. To clear variables when a script is finished, use a at_exit handler in a 'require'd file. Don't define at_exit handler in the script itself, or the at_exit handler additively defined repeatedly.

Note that the ARGV variable is not useful for CGI scripts evaluated by cgi-ruby module. You need to use QUERY_STRING environment variable instead.
Back
Akira Higuchi