dynamic_limit_req_redis

Configures connection parameters for the Redis database used by the dynamic request limiting module.

Syntaxdynamic_limit_req_redis unix_socket | port=[number] requirepass=[password];
Defaultport 6379
Contexthttp
Arguments1-3

Description

The dynamic_limit_req_redis directive is part of the ngx_dynamic_limit_req_module, which dynamically locks IP addresses and releases them periodically based on request rates. This directive allows you to set connection parameters for Redis, a popular in-memory data structure store that the module uses for state management regarding excessive requests.

It accepts up to three arguments: unix_socket, port=[number], and requirepass=[password]. The unix_socket provides a method to connect to the Redis server using a Unix socket, while the port parameter specifies the port number for TCP connections to Redis, defaulting to 6379. If Redis is configured to require authentication, you can use the requirepass option to provide the necessary password. This flexibility accommodates various deployment scenarios, including instances where Redis is behind authentication or when different connection methods are required.

The Redis connection plays a crucial role in maintaining the state of requests, enabling effective rate limiting by accessing shared data across multiple NGINX worker processes. Failure to configure this directive correctly may lead to issues such as being unable to communicate with Redis, thus hindering the intended dynamic request limiting functionality.

Config Example

dynamic_limit_req_redis unix_socket requirepass=comeback;
dynamic_limit_req_zone $binary_remote_addr zone=sms:5m rate=5r/m redis=/tmp/redis.sock block_second=1800;
dynamic_limit_req zone=sms burst=3 nodelay;

Ensure that the Redis server is running and accessible by NGINX.

Check permissions on the Unix socket if using unix_socket connection.

The Redis authentication password must be correct to avoid connection failures.

← Back to all directives