Contained WithinFind More DocumentationFeatured Support Resources | Download this book in PDF (702 KB)
Chapter 3 Using Common Gateway InterfaceCommon Gateway Interface (CGI) programs run on the server and generate a response to return to the requesting client. CGI programs can be written in various languages, including C, C++, Java, Perl, and as shell scripts. CGI programs are executed through URL invocation. For information about writing CGI programs, see: http://hoohoo.ncsa.uiuc.edu/cgi/overview.html Sun Java System Web Server 7.0 complies with the CGI specification version 1.1. This chapter has the following sections: Configuring CGI SettingsYou can configure the Web Server to recognize and execute CGI programs. This section discusses the following topics:
|
total 14
lrwxrwxrwx 1 root other 8 Jan 13 03:32 bin -\> /usr/bin
drwxr-xr-x 2 user group 512 Jan 13 03:42 cgi-bin
drwxr-xr-x 2 root other 512 Jan 13 03:28 dev
drwxr-xr-x 2 user group 512 Jan 13 03:26 docs
drwxr-xr-x 2 root other 512 Jan 13 03:33 etc
lrwxrwxrwx 1 root other 8 Jan 13 03:30 lib -\> /usr/lib
drwxr-xr-x 4 root other 512 Jan 13 03:32 usr
|
Set the virtual server’s chroot directory in one of the following ways:
Modify the obj.conf file.
Use the chroot parameter of the send-cgi Service SAF in the obj.conf file. For detailed instructions, see the Sun Java System Web Server 7.0 Administrator’s Configuration File Reference.
Use the Admin Console.
Select Common Tasks tab > CGI Directories from the Virtual Server Tasks list.
The CGI Settings window is displayed.
Enter the Chroot directory.
For detailed instructions, see the Sun Java System Web Server 7.0 Administrator’s Guide.
Use the set-cgi-prop command.
Example: ./wadm set-cgi-prop --user=admin --password-file=admin.pwd --host=serverhost --port=8989 --config=config1 chroot=vs_dir
For information on the set-cgi-prop command, see the Sun Java System Web Server 7.0 Administrator’s Configuration File Reference.
To add CGI programs to the server, do one of the following:
Store the program file in a CGI directory (if there are any).
Give it a file name that the server recognizes as a CGI program and put it in any directory at or below the document root (if CGI file type recognition has been activated).
On UNIX platforms, make sure the program file has execute permissions set.
The priority of a CGI program can be set using the nice parameter of the send-cgi function. This is a UNIX-only parameter and accepts an increment that determines the CGI program’s priority relative to the priority of the server process. Typically, the server is run with a nice value of 0 and the nice increment can be between 0 and 19.
The CGI program runs at the same priority as server
The CGI program runs at a much lower priority than the server
As with all other CGI variables, the nice value can be configured per virtual server.
While it is possible to increase the priority of the CGI program above that of the server by specifying a nice increment of -1, Sun does not recommended you to do so.
For more information about send-cgi, see the Sun Java System Web Server 7.0 Administrator’s Configuration File Reference.
You can configure CGI variables for a virtual server either using the Admin Console or using the CLI. The following procedure describes the steps:
Configure CGI variables.
Shell CGI is a text file that contains commands for the Bourne Shell command interpreter. You can use any text editor to create a shell CGI program. Shell CGI programs are typically given the suffix .sh.
For information about installing CGI and shell CGI programs on Windows using the Admin Console, see the Sun Java System Web Server 7.0 Administrator’s Guide.
Web Server 7.0 bundles a Perl interpreter to run CGI programs that are written in the Perl programming language. The Perl interpreter is located at install_dir/lib/perl.
On Windows platform, file associations need to be in place for CGI programs to run. Files with a .pl filename extension need to be associated with the Perl interpreter executable before they can be executed as CGI programs. To create an association for Perl programs to run as CGI programs, perform the following steps:
Open a command-line window from start-> run -> cmd.
Create an association for Perl programs.
C:\>assoc .pl=perl
C:\>ftype perl="c:\WS7\lib\perl\perl.exe" "%1"
You cannot run CGIs using Perl 5.6.x with the -w flag. Instead, include the following code in the Perl script:
use warnings;
This section describes the steps to configure the server to execute Perl programs as CGI programs.
Create a simple Perl program called hello.pl.
Create a directory for this program. By convention, this directory is named as the cgi-bin directory though you can name it whatever you like.
It is recommended that you create the cgi-bin directory under the instance configuration directory. For example:
mkdir /var/opt/SUNWwbsvr7/cgi-bin |
Copy the hello.pl file into the /var/opt/SUNWwbsvr7/cgi-bin directory.
Select Common Tasks tab > CGI Directories from the Virtual Servers Tasks list.
The CGI Settings window is displayed.
Click the New button in the CGI Directories section.
The Add CGI Directories window is displayed.
Enter the Prefix and the CGI Directory path. Choose whether the program is a CGI or a ShellCGI program.
For example (On UNIX platforms):
Prefix: /cgi-bin
CGI Directory: /var/opt/SUNWwbsvr7/cgi-bin
On Windows platforms:
Prefix: \cgi-bin
CGI Directory: c:\sun\webserver7\cgi-bin
The CGI directory you specified must have execute permissions.
Click Save to save the changes. Access the program from a browser window.
Open a browser window. If your server is called acme, running on port 2222), type http://acme:2222/cgi-bin/hello.pl.
Displays the message “Hello World” on the browser window.
You can change the CGI settings globally for all available virtual servers. You can either use the Administration Console or the CLI.
You can use either the Admin Console or the CLI to change the global CGI settings:
Using the Admin Console:
Click the Configuration tab.
List of available configurations is displayed.
Select a configuration from the list.
Select Performance tab > CGI subtab.
The CGI Settings window is displayed.
Specify the values for the following settings:
CGI Timeout Settings:
Timeout (CGIExpirationTimeout) Specifies the time in seconds after which the server terminates a long-running CGI program.
Idle Timeout(CGIStubIdleTimeout) Causes the server to kill any CGIStub processes that have been idle for the number of seconds set by this directive. Once the number of processes is at MinCGIStubs, the server does not kill any more processes.
CGI Stub Process Settings:
Timeout Time in seconds after which an unused CGI stub process is terminated.
CGI Stub Excecutable Controls the number of processes that are started by default. The first CGIStub process is not started until a CGI program has been accessed. The default value is 2. If you have a init-cgi directive in the magnus.conf file, the minimum number of CGIStub processes are spawned at startup. Controls the number of processes that are started by default.
Minimum Stub Size Controls the maximum number of CGIStub processes the server can spawn. This is the maximum concurrent CGIStub processes in execution, not the maximum number of pending requests. The value must be less than the Maximum Stub Size.
Maximum Stub Size Controls the maximum number of CGIStub processes the server can spawn. This is the maximum concurrent CGIStub processes in execution, not the maximum number of pending requests.
For more information about these global CGI settings, see the description of the magnus.conf file in the Sun Java System Web Server 7.0 Administrator’s Configuration File Reference.
Click Save to apply your changes.
Using the set-cgi-prop command.
Example:
./wadm set-cgi-prop --user=admin --password-file=admin.pwd --host=serverhost --port=8989 --config=config1 timeout=10 max-cgistubs=20 idle-timeout=600 min-cgistubs=10 cgistub-idle-timeout=60 cgistub-path=../../lib/Cgistub
For more information on the set-cgi-prop command, see the Sun Java System Web Server 7.0 CLI Reference Manual.
In addition to the standard CGI variables, you can use the Sun Java System Web Server CGI variables in CGI programs to access information about the client certificate if the server is running in secure mode. The CLIENT_CERT and REVOCATION variables are available only when client certificate-based authentication is enabled.
The following table lists the Sun Java System Web Server CGI variables.
Table 3–1 CGI Variables|
Variable |
Description |
|---|---|
|
SERVER_URL |
URL of the server that the client requested |
|
HTTP_xxx |
An incoming HTTP request header, where xxx is the name of the header |
|
HTTPS |
ON if the server is in secure mode, otherwise OFF |
|
HTTPS_KEYSIZE |
Keysize of the SSL handshake (available if the server is in secure mode) |
|
HTTPS_SECRETKEYSIZE |
Keysize of the secret part of the SSL handshake (available if the server is in secure mode) |
|
HTTPS_SESSIONID |
Session ID for the connection (available if the server is in secure mode) |
|
Certificate the client provided (binary DER format) |
|
|
CLIENT_CERT_SUBJECT_DN |
Distinguished Name of the subject of the client certificate |
|
CLIENT_CERT_SUBJECT_OU |
Organization Unit of the subject of the client certificate |
|
CLIENT_CERT_SUBJECT_O |
Organization of the subject of the client certificate |
|
CLIENT_CERT_SUBJECT_C |
Country of the subject of the client certificate |
|
CLIENT_CERT_SUBJECT_L |
Location of the subject of the client certificate |
|
CLIENT_CERT_SUBJECT_ST |
State of the subject of the client certificate |
|
CLIENT_CERT_SUBJECT_E |
E-mail of the subject of the client certificate |
|
CLIENT_CERT_SUBJECT_UID |
UID part of the CN of the subject of the client certificate |
|
CLIENT_CERT_ISSUER_DN |
Distinguished Name of the issuer of the client certificate |
|
CLIENT_CERT_ISSUER_OU |
Organization Unit of the issuer of the client certificate |
|
CLIENT_CERT_ISSUER_O |
Organization of the issuer of the client certificate |
|
CLIENT_CERT_ISSUER_C |
Country of the issuer of the client certificate |
|
CLIENT_CERT_ISSUER_L |
Location of the issuer of the client certificate |
|
CLIENT_CERT_ISSUER_ST |
State of the issuer of the client certificate |
|
CLIENT_CERT_ISSUER_E |
E-mail of the issuer of the client certificate |
|
CLIENT_CERT_ISSUER_UID |
UID part of the CN of the issuer of the client certificate |
|
CLIENT_CERT_VALIDITY_START |
Start date of the certificate |
|
CLIENT_CERT_VALIDITY_EXIRES |
Expiration date of the certificate |
|
CLIENT_CERT_EXTENSION_xxx |
Certificate extension, where xxx is the name of the extension |
|
REVOCATION_METHOD |
Name of the certificate revocation method if it exists |
|
REVOCATION_STATUS |
Status of certificate revocation if it exists |
FastCGI is an enhancement to the CGI, which is a standard for interfacing external applications with Web Servers. Like CGI, FastCGI applications run in separate, isolated processes. FastCGI plug-in allows Web Server to safely work with popular third-party dynamic content generation technologies (such as Perl and Python) in a scalable way.
For information on creating FastCGI applications, see the FastCGI Plug-in chapter in the Sun Java System Web Server 7.0 Administrator’s Guide.