Nginx's limit_req_zone and limit_req directives let you cap requests per IP or key. Use our generator to create the correct shared memory zone and apply it to any location block.
Define a shared-memory zone keyed by client address in the http block, then apply it in a location.
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
server {
location /api/ {
limit_req zone=api burst=20 nodelay;
limit_req_status 429;
}
}burst allows short spikes above the rate. nodelay serves the burst immediately instead of spacing requests out; requests beyond the burst are rejected.
Open the Rate limiting generator
429 Too Many Requests. Nginx defaults to 503, so set limit_req_status 429.
$binary_remote_addr is the CDN address. Use the real client IP via the realip module before the limit is evaluated.