rate_limit_pass

The `rate_limit_pass` directive specifies the upstream server to use for checking and enforcing rate limits in NGINX.

Syntaxrate_limit_pass
Defaultnone
Contexthttp, server, location
Arguments1

Description

The rate_limit_pass directive in NGINX is part of a Redis-backed rate limiting module that enhances the server's ability to control request rates based on defined criteria. This directive tells NGINX to pass the rate limiting decision-making process to a specified upstream Redis server. By supplying the argument to this directive, the server can synchronize rate-limiting data with Redis, allowing for shared control of request rates across multiple server instances or containers, which is beneficial for high-traffic environments.

When implemented in conjunction with the geo and map directives, rate_limit_pass leverages remote address information or custom variables defined within the request context to determine the appropriate rate limits to apply. The rate limit configurations, including request thresholds and burst capacities, are specified within the same location block, which enhances flexibility. Furthermore, if the rate is exceeded, a predefined HTTP status is returned, configured through the rate_limit_status directive.

It's crucial to note that the directives need to be correctly set up within the NGINX configuration to prevent any unexpected issues when interacting with Redis. The directive works within the contexts of http, server, or location blocks, ensuring it integrates seamlessly in various routing scenarios.

Config Example

upstream redis {
   server 127.0.0.1:6379;
   keepalive 1024;
}

location = /limit {
    rate_limit $limit_key requests=15 period=1m burst=20;
    rate_limit_pass redis;
}

Ensure the upstream Redis server is correctly configured and reachable by NGINX.

Using incorrect keys or values in the rate limiting logic can lead to unintended rate-limiting behavior.

Be mindful of the maximum length of keys used; exceeding 65535 bytes will cause errors.

← Back to all directives