dynamic_limit_req_status

The dynamic_limit_req_status directive sets the HTTP status code returned to clients when their requests exceed the defined limit.

Syntaxdynamic_limit_req_status code;
Defaultnone
Contexthttp, server, location, if in location
Arguments1

Description

The dynamic_limit_req_status directive is part of the NGINX Dynamic Limit Request module, which facilitates the dynamic locking of IP addresses that exceed request thresholds. When specific limits on a certain key (like an IP address) are exceeded, this directive allows the configuration of a custom HTTP status code that NGINX will return to clients. This capability is crucial for managing how clients receive feedback when they are rate-limited, ensuring they understand that their requests are not being processed due to exceeding limits.

This directive can be set within the contexts of HTTP, server, or location blocks, as well as within conditional blocks inside location contexts. The argument for this directive must be a valid HTTP status code (typically in the 400-599 range), allowing administrators to customize how they handle such situations. This flexibility enables you to define a smoother user experience, potentially providing clients with error messages specific to your application's logic. Without a proper status code, clients might not understand why their requests were denied or delayed, which could lead to frustration and confusion.

It's essential to properly configure this directive in conjunction with the other directive parameters such as dynamic_limit_req_zone and dynamic_limit_req, as they collectively dictate the terms of request handling and logging. If not configured correctly, it could result in non-optimal behaviors or user experiences when clients exceed request limits.

Config Example

http {
    dynamic_limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
    dynamic_limit_req_status 429;
}

server {
    location / {
        dynamic_limit_req zone=one burst=5 nodelay;
    }
}

Ensure the status code is within the valid HTTP range (400-599) to avoid unexpected errors.

Be aware that using a status code like 200 may cause confusion as it implies success despite exceeding limits.

Combining multiple directives for limit requests may result in unexpected behaviors if not properly configured.

← Back to all directives