rate_limit_quantity

Sets the quantity of requests allowed before rate limiting kicks in using the Redis backed rate limit module.

Syntaxrate_limit_quantity number;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The rate_limit_quantity directive specifies the threshold at which requests should be limited for a specific key identified in the NGINX configuration. This directive is particularly useful when designing APIs or web applications where certain clients should be restricted from making excess requests within a defined timeframe. When the number of requests from a client exceeds the rate_limit_quantity specified, subsequent requests will receive a rate-limited response, typically the configured status code (like 429 Too Many Requests).

In the context of the Redis backed rate limit module, this directive utilizes Redis as a backend store to maintain the state and history of requests made by clients. The requests are measured within a specified period defined by the period parameter of the rate_limit directive. After exceeding the set quantity of requests, responses from the server may be controlled by how the module interacts with the Redis database to surface the appropriate error codes or responses. Moreover, it can be used in combination with bursts defined by burst parameters to accommodate scenarios where sudden spikes in traffic are allowable up to a certain threshold before stricter limits apply.

The <location> or <server> blocks allow the flexibility to apply different rate limits based on the specific endpoint or server configurations. This directive provides a granular approach to manage load effectively while also ensuring client requests are processed fairly and within the required limits, enhancing overall stability and performance of NGINX handling multiple clients.

Config Example

location = /quota {
    rate_limit $limit_key requests=15 period=1m burst=20;
    rate_limit_quantity 0;
    rate_limit_pass redis;
    rate_limit_headers on;
}

Ensure that Redis is properly configured and reachable, as failures in connectivity can lead to unexpected request denials.

Using a rate_limit_quantity of 0 disables rate limiting, which may be unintentionally skipped over in configuration revisions.

Make certain that the rate_limit directive is correctly specified as it sets up the context for the rate_limit_quantity; otherwise, the directive can appear to have no effect.

← Back to all directives