log_subrequest

The `log_subrequest` directive controls whether subrequests are logged in NGINX's error logs.

Syntaxlog_subrequest on | off;
Defaultoff
Contexthttp, server, location
Argumentsflag

Description

The log_subrequest directive, used within the http, server, and location contexts, allows you to specify whether subrequests made by the server should be logged. A subrequest is an internal request made by NGINX, typically generated by directives such as include or try_files. By default, logs of these subrequests can clutter the main error log, making it difficult to spot important issues. This directive lets you suppress those logs, ensuring your main logs only contain significant top-level request information.

When enabled (set to on), subrequests will be logged at the error level, which means that any issues occurring during these internal requests will be recorded in the NGINX error logs. Conversely, setting it to off disables logging of these subrequests, reducing the volume of logged data. This is particularly useful in high-traffic scenarios where subrequests can be numerous and where logging each one could impact performance and make log files large and unwieldy.

The syntax for this directive is straightforward, taking a flag value; thus, it can be easily integrated into existing configurations with minimal effort. Its judicious use is recommended based on the needs for monitoring versus file size or performance considerations, and it can be applied per context to refine what information is captured in your logs.

Config Example

http {
    log_subrequest on;

    server {
        location /example {
            try_files $uri /subrequest;
        }
    }
}

Be mindful that logging numerous subrequests can lead to large log files, affecting performance and log file management.

Remember to configure the error log level appropriately to capture the detailed error messages related to subrequests when logging is enabled.

← Back to all directives