Master Nginx Rate Limiting: Configure limit_req_zone and limit_req in Minutes
This guide explains how to configure Nginx rate limiting using limit_req_zone and limit_req directives, covering syntax, parameters, burst handling, and a complete example that demonstrates setting a shared memory zone, request rate, burst buffer, and nodelay behavior for efficient traffic control.
1. Nginx Rate Limiting Configuration
limit_req_zone is used to limit the number of requests per unit time (rate limiting) using the leaky bucket algorithm.
Parameters of limit_req_zone
Syntax: limit_req zone=name [burst=number] [nodelay]; Default: —
Context: http, server, location
(1) Definition
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;The first parameter $binary_remote_addr uses the client IP address as the key; the “binary_” prefix reduces memory usage.
The second parameter zone=one:10m creates a 10 MB shared memory zone named one to store request counters.
The third parameter rate=10r/s allows up to 10 requests per second for each key (e.g., 30r/m is also possible).
(2) Usage
limit_req zone=one burst=30 nodelay;The first argument selects the zone defined above. burst=30 creates a buffer of size 30 for bursts that exceed the rate limit. nodelay makes excess requests that fill the buffer return a 503 error immediately; without it, requests are queued.
(3) Example
http {
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
server {
location /search/ {
limit_req zone=one burst=30 nodelay;
}
}
}Practical DevOps Architecture
Hands‑on DevOps operations using Docker, K8s, Jenkins, and Ansible—empowering ops professionals to grow together through sharing, discussion, knowledge consolidation, and continuous improvement.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
