Skip to content

How to Configure Nginx Request Rate Limiting

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Configure Nginx Request Rate Limiting. We cover key concepts, practical examples, and best practices.

Rate limiting with limit_req protects against request floods and abuse. Configuring burst and nodelay provides flexibility for traffic spikes. This guide walks through the specific troubleshooting steps to diagnose and resolve rate limiting issues.

Before You Begin

Before you begin, be sure to have the following in place:

  • A Linux server with the relevant software installed
  • Access to the command line interface
  • Appropriate permissions (root or sudo)

Quick Fix

Wrong

No rate limiting (server vulnerable to abuse)

Wrong: No request rate limiting

limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;\nlimit_req zone=mylimit burst=20 nodelay;

Right: Rate limiting with burst and nodelay

Output

Rate limit configured:\n  Zone: mylimit (10MB)\n  Rate: 10 requests/second\n  Burst: 20\n  Mode: nodelay

Prevention

To avoid future issues, follow these best practices:

  • Define limit_req_zone in http context (shared across workers)
  • Set realistic rates based on expected traffic
  • Use burst to allow short traffic spikes
  • Use nodelay to process burst requests immediately (not delayed)
  • Set limit_req_status to customize the 429 response

DodaTech Tools

For further assistance with any of the above issues, consider using DodaTech consulting services or DodaTech tutorials for more in-depth guidance.

Common Mistakes with limit req

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world NGINX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

How does limit_req burst work?|||The burst parameter creates a queue of excess requests. Without nodelay, queued requests are delayed. With nodelay, they are processed immediately up to the burst limit.
What happens when the rate limit is exceeded? Nginx returns 503 Service Unavailable (or 429 with limit_req_status 429) for excess requests.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro