echo_exec

The `echo_exec` directive executes a specified command and optionally captures its output.

Syntaxecho_exec command [options];
Defaultnone
Contextlocation, if in location
Arguments1-2

Description

The echo_exec directive in the NGINX Echo module is designed to execute shell commands directly from the NGINX configuration file. It accepts one or two arguments: the command to execute and an optional flag that dictates how the output should be handled. When a single argument is provided, the directive will simply run the command in a shell environment. If two arguments are specified, the first one represents the command, and the second defines options for output processing, such as whether to capture the command's output for use in further processing.

The execution of the command occurs in the context of handling a client request. This allows for dynamic command execution based on HTTP requests. The output produced by the command can be returned to the client depending on the configuration. The directive is particularly useful in scenarios where real-time data must be fetched or processed on-the-fly, such as executing scripts that generate configuration metrics or status reports.

It's important to note that the echo_exec directive can pose security risks, especially if the input to the command is derived from user input. Therefore, careful validation of input is required. Moreover, the performance of the NGINX server may be impacted since executing shell commands introduces overhead.

Config Example

location /execute {
    echo_exec "ls -l /tmp";
}

Ensure that the command you are trying to run is safe and does not expose vulnerabilities.

Be mindful of the performance impact when executing heavy commands.

Commands that generate large amounts of output may hit buffer limits.

← Back to all directives