dynamic_limit_req_zone

The `dynamic_limit_req_zone` directive configures a shared memory zone to track and limit excessive request rates per IP address or specific key.

Syntaxdynamic_limit_req_zone key zone=name:size rate=rate [sync] redis=address block_second=time;
Defaultnone
Contexthttp
Arguments5

Description

The dynamic_limit_req_zone directive is an essential component of the ngx_dynamic_limit_req_module, utilized to dynamically manage IP request rates and protect against abuse. It establishes a shared memory area where the current state of request rates for designated keys is maintained, allowing NGINX to control the frequency of requests that a single client can make to the server.

This directive accepts several parameters:
- key: Specifies the key to track requests, which can be a combination of text and variables (e.g., $binary_remote_addr enables tracking based on the client IP address).
- zone=name:size: Defines the name and size of the shared memory zone; name is an identifier, and size defines the amount of memory allocated (e.g., 5m for 5 megabytes).
- rate=rate: Establishes the maximum request rate (in requests per second) allowed for the key, expressed as integers corresponding to 0.001 requests per second (e.g., 5r/m for five requests per minute).
- sync: Optional flag for enabling synchronization between processes.
- redis=address: Specifies the Redis server location for storing request states externally.
- block_second=time: Defines a time duration (in seconds) for which an IP should be blocked after exceeding the allowed rate.

Overall, dynamic_limit_req_zone helps mitigate issues like DDoS attacks by controlling the request flow and allowing for dynamic adjustments based on traffic patterns.

Config Example

dynamic_limit_req_zone $binary_remote_addr zone=sms:10m rate=10r/s redis=127.0.0.1 block_second=600;

Ensure the Redis server is running and accessible by NGINX, or the directive will fail to operate as intended.

If the shared memory size is too small, it may lead to insufficient tracking of concurrent requests, causing miscalculations in request limits.

Remember to properly configure the Redis parameters if using the redis option; missing or incorrect settings can lead to failures in request rate tracking.

← Back to all directives