rewrite_log

The rewrite_log directive enables logging of rewrite processing details for requests.

Syntaxrewrite_log on | off;
Defaultoff
Contexthttp, server, location, if in server, if in location
Argumentsflag

Description

The rewrite_log directive is part of the NGINX HTTP Core module and is utilized to log detailed information regarding the rewrite processing of requests. When enabled, it helps developers and system administrators debug complex rewrite rules by providing insights into the rewrite engine's operations. This can be particularly helpful in identifying issues within rewrite rules, such as incorrect redirects or unexpected behavior in URL handling.

The directive accepts a flag parameter, where setting it to 'on' enables logging, and 'off' disables it. The logs generated include entries for each rewrite cycle, along with the conditions and replacements being made. This feature is typically used during the development and testing stages of configuration, as the added verbosity can lead to performance degradation in a production environment if left enabled.

When placed in the appropriate context (http, server, location, or if statements within these contexts), it controls the log output specifically for those blocks. However, it is essential to use it judiciously, as logging every rewrite process can quickly fill log files and potentially lead to I/O overhead.

Config Example

server {
    listen 80;
    server_name example.com;

    rewrite_log on;

    location /old-page {
        rewrite ^/old-page/(.*) /new-page/$1 last;
    }
}

Enabling rewrite_log increases the verbosity of log files, which can impact performance and lead to large log sizes in production environments.

Ensure log rotation is set up if rewrite_log is enabled, to prevent excessive disk usage.

← Back to all directives