upstream_log

The upstream_log directive records logs for requests sent to upstream servers in a defined format.

Syntaxupstream_log path format;
Defaultnone
Contexthttp, server, location, if in location, limit_except
Arguments1+

Description

The upstream_log directive is utilized to write detailed logs for requests directed to upstream servers in the NGINX server configuration. It operates similarly to the existing access_log functionality, but it specifically tracks and logs data at the conclusion of each upstream request. This includes cases where multiple upstream servers are contacted during the processing of a single request, ensuring that log entries capture all interaction with these servers. Additionally, if an internal redirect occurs, such as with X-Accel-Redirect or error_page, a log entry will also be created after each contact, thereby providing comprehensive request tracking.

Config Example

http {
    log_format upstream '$remote_addr $upstream_last_addr [$time_local] "$upstream_method $upstream_uri" '
                     '$upstream_last_status $upstream_last_response_length';

    upstream cluster {
        server 192.168.0.1:80;
        server 192.168.0.2:80;
    }

    server {
        listen 80;
        upstream_log logs/upstream.log upstream;
        location / {
            proxy_pass http://cluster;
        }
    }
}

Ensure the format specified in upstream_log is correctly defined, as an incorrectly formatted log can lead to parse errors.

This module is considered experimental; users should be cautious and test configurations thoroughly in non-production environments.

Multiple upstream_log directives in the same context can lead to confusion; it is best practice to keep logging centralized.

← Back to all directives