---
name: "mod_cgi"
section: "3erl"
platform: "linux"
package: "erlang-manpages"
version: "1:10.b.1a-1"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/mod_cgi"
---

# mod\_cgi(3erl)

Invoking of CGI scripts.

## NAME

mod\_cgi - Invoking of CGI scripts.

## DESCRIPTION

This module makes it possible to execute vanilla CGI (Common Gateway Interface) scripts in the server. A file that matches the definition of a  ScriptAlias config directive is treated as a CGI script. A CGI script is executed by the server and it's output is returned to the client.

mod\_cgi sends the response transfer-encoded to HTTP/1.1 compatible clients. The content is transfer encoded with the chunked encoding algorithm. This means that the Content-Length field not should be in the HTTP header. Furthermore assumes mod\_cgi that the first chunk of data from the script is the only chunk with header information. If the first chunk of data from the script does not contain *"\\r\\n\\r\\n"* mod\_cgi assumes that no HTTP-header information is to come from the script. A chunk of data with HTTP header fields from a script might look something like this:

```
      "Content-Type:text/plain\r\nAccept-Ranges:none\r\n\r\nsome very plain text"
```

Support for CGI-1.1 is implemented in accordance with the CGI-1.1 specification \<http://hoohoo.ncsa.uiuc.edu/cgi/\>.

### Note:

CGI is currently available for Erlang/OTP running on a UNIX platform. These number of platforms will be increased.

- \*

  ScriptNoCache

- \*

  ScriptTimeout

## DIRECTIVE: ScriptNoCache

*Syntax:* *ScritpNoCache* true \| false\
\
  *Default:* - false -\
\
  *Module:* mod\_cgi(3)

If ScriptNoCache is set to true the Web server will by default add the header fields necessary to prevent proxies from caching the page. Generally this is something you want.

```
ScriptNoCache true
```

## DIRECTIVE: ScriptTimeout

*Syntax:* *ScritpTimeout* Seconds\
\
  *Default:* 15 \
\
  *Module:* mod\_cgi(3)

The time in seconds the web server will wait between each chunk of data from the script. If the CGI-script not delivers any data before the timeout the connection to the client will be closed.

```
ScriptTimeout  15
```

## EWSAPI MODULE INTERACTION

Uses the following EWSAPI interaction data, if available:

- ***{new\_request\_uri, NewRequestURI}*:**

  as defined in mod\_actions(3).

- ***{remote\_user, RemoteUser}*:**

  as defined in mod\_auth(3).

Uses the following EWSAPI functions:

- \*

  mod\_alias:real\_name/3

- \*

  mod\_alias:real\_script\_name/3

- \*

  mod\_cgi:env/3

- \*

  mod\_cgi:status\_code:env/1

This module furthermore exports a batch of functions to be used by other EWSAPI modules:

## EXPORTS

**env(Info,Script,AfterScript) -\> EnvString**\

- Types

  Info = mod\_record()\
   Script = AfterScript = EnvString = string()\

### Note:

This function should only be used when implementing CGI-1.1 functionality on UNIX platforms.

*open\_port/2* is normally used to start and interact with CGI scripts. *open\_port/2* takes an external program as input; *[env(1)](/env/1.md)* (GNU Shell Utility) is typically used in the case of a CGI script. *[env(1)](/env/1.md)* execute the CGI script in a modified environment and takes the CGI script and a string of environment variables as input. *env/3* returns an appropriate CGI-1.1 environment variable string to be used for this purpose. The environment variables in the string are those defined in the CGI-1.1 specification \<http://hoohoo.ncsa.uiuc.edu/cgi/\>. *mod\_record()* is a record as defined in the EWSAPI Module Programming in the Inets Users Guide.

**status\_code(CGIOutput) -\> {ok,StatusCode} \| {error,Reason}**\

- Types

  CGIOutput = Reason = string()\
   StatusCode = integer()\

Certain output from CGI scripts has a special meaning, as described in the CGI specification \<http://hoohoo.ncsa.uiuc.edu/cgi/\>, for example if *"Location: http://www.yahoo.com\\n\\n"* is returned from a CGI script the client gets automatically redirected to Yahoo! \<http://www.yahoo.com\>, using the HTTP 302 status code (RFC 1945).

## SEE ALSO

httpd(3), mod\_auth(3), mod\_security(3), mod\_alias(3), mod\_esi(3), mod\_include(3)

## AUTHORS

```
Joakim Grebenö  - support@erlang.ericsson.se
Mattias Nilsson  - support@erlang.ericsson.se
```
