cgi_pass

The `cgi_pass` directive in NGINX passes requests to a CGI script for processing.

Syntaxcgi_pass path;
Defaultnone
Contextserver, location
Arguments1+

Description

The cgi_pass directive is part of the CGI support module in NGINX, allowing web server requests to be processed by an external CGI program. This directive can be used within the server or location contexts to define the script or the path to the program that will handle specific request URIs. When a request matches a location where cgi_pass is defined, NGINX prepares the request parameters and invokes the CGI script. The environmental variables and request headers are passed to the script, which can generate dynamic content or provide certain operations in response to the client's request.

The cgi_pass directive takes one or more arguments, which typically represent the path to the script or the URI to be handled. This feature is particularly useful in scenarios where existing CGI scripts are integrated into an NGINX workflow. It supports configurability in terms of the working directory, interpreter to be used, and options regarding how to handle request bodies. The behavior of the CGI process is controlled through various configuration options, including setting timeouts, managing the stderr output, and defining custom extension variables to be passed to the script.

Config Example

location /cgi-bin/ {
    cgi_pass /path/to/cgi-bin/script.sh;
}

Ensure that the CGI script is executable and properly configured.

Incorrect file paths can lead to 404 errors or broken functionality.

The CGI scripts should be optimized for performance to avoid high latency issues in request handling.

← Back to all directives