Nginx Rate Limiting Configuration

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.

Zone and limit

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 and nodelay

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

Frequently asked questions

Which status code should rate limiting return?

429 Too Many Requests. Nginx defaults to 503, so set limit_req_status 429.

Why does limiting not work behind a CDN?

$binary_remote_addr is the CDN address. Use the real client IP via the realip module before the limit is evaluated.

Guides