Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Use Nginx as an origin-side traffic filter, not as your only DDoS defense. Configure request-rate limits for costly endpoints, concurrent-connection limits for each client key, bandwidth controls where appropriate, and TCP connection limits for stream services. Restore the real client IP only from trusted proxies, begin in dry-run mode, and tune limits from normal traffic. If an attack fills the server’s Internet connection before packets reach Nginx, put a CDN or managed DDoS-scrubbing service in front of the origin.

The configuration below gives you a safe starting pattern. Its values are examples, not universal thresholds: a public login form, an API, a file download, and a streaming service have very different legitimate traffic profiles.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What Nginx can—and cannot—block

Nginx can absorb and reject many application-layer attacks before they consume as much upstream capacity. Its HTTP modules can regulate request rates with a leaky-bucket algorithm, cap simultaneous connections, and return a deliberate status such as 429 Too Many Requests. The same concepts can be applied to TCP services in the stream context.

Those controls operate after traffic has reached the host. A volumetric attack that saturates the origin’s access link, firewall, or provider edge prevents legitimate requests—and Nginx itself—from receiving the traffic. In that situation, local rules cannot solve the congestion. Route the service through an upstream CDN or managed scrubbing provider, restrict the origin firewall to that provider where the architecture allows it, and ask the network provider to mitigate traffic upstream.

#1 Best Overall
FortiGate-40F Firewall Appliance - 5 Gigabit Ethernet RJ45 Ports, Ideal for Small Businesses (Appliance Only, No Subscription) (FG-40F)
  • Compact and Efficient Design: The FortiGate 40F is designed for small to mid-sized businesses and enterprise branch offices, featuring a compact, fanless desktop form factor that ensures quiet operation and minimizes space usage.
  • Robust Connectivity Options: Equipped with 5 GE RJ45 ports, including 1 WAN port and 4 internal ports, this model provides essential connectivity and flexibility for various network configurations in a small-scale environment.
  • High-Performance Security: Offers up to 1 Gbps IPS throughput and 600 Mbps threat protection throughput, using Fortinet’s purpose-built security processor technology to deliver industry-leading performance and protection for SSL encrypted traffic.
  • Advanced Threat Protection: Integrated with Fortinet’s AI-powered FortiGuard Labs, the FortiGate 40F offers comprehensive cybersecurity, identifying and mitigating both known and unknown threats to maintain robust security across your network.
  • Simplified Management and Deployment: Features a user-friendly management console that provides comprehensive network automation and visibility, coupled with Zero Touch Integration with Fortinet’s Security Fabric for easy deployment.
Control Layer and key Typical action Works if the origin link is saturated?
Request-rate limiting HTTP; usually a client-IP expression such as $binary_remote_addr Delay, immediately serve within a burst, or reject excess requests No
Concurrent-connection limiting HTTP; client key or another expression Reject connections above the configured count No
Bandwidth limiting HTTP response; per connection Reduce transfer speed No
Stream connection limiting TCP/UDP stream; source key Cap simultaneous stream connections No
Upstream scrubbing Provider network edge Filter and absorb traffic before it reaches the origin Yes, when correctly deployed

Think of Nginx as one layer in a defense-in-depth design. It is particularly useful when the attacker can reach the server but is sending too many HTTP requests, opening too many connections, or repeatedly invoking expensive application paths.

Prepare the origin before adding limits

Inventory legitimate traffic

Measure normal request rates and concurrency by endpoint rather than choosing one limit for the whole site. Record separate baselines for anonymous and authenticated users, normal business hours and peaks, geographic regions, mobile networks, corporate networks, and known automation. Expensive operations such as login, password reset, search, report generation, checkout, and upload generally need tighter controls than static assets.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Count requests per second and concurrent connections at each important location.
  • Measure response latency and upstream queueing while traffic is normal.
  • Identify shared networks, carrier-grade NAT, forward proxies, and load balancers that make many users appear under one address.
  • List trusted monitoring systems, API clients, and internal services that may require a separate policy.

Confirm your Nginx build and configuration boundaries

limit_req_zone and limit_conn_zone are declared in the http context. Their enforcement directives belong in an http, server, or location context as permitted by the module. Stream limits use the separate stream context. Validate every change with nginx -t before reloading.

Configure HTTP request-rate limiting

Define a shared zone and a per-endpoint policy

The shared-memory zone stores the counters used by workers. The rate is a sustained processing rate, while burst allows a temporary queue of requests above that rate. The following example deliberately protects login more tightly than ordinary pages:

http {
    # Tune the size and rate from measured legitimate traffic.
    limit_req_zone  $binary_remote_addr  zone=per_ip_req:10m  rate=5r/s;
    limit_conn_zone $binary_remote_addr  zone=per_ip_conn:10m;

    server {
        location = /login {
            limit_req zone=per_ip_req burst=10 nodelay;
            limit_conn per_ip_conn 10;
            limit_req_dry_run on;
            limit_req_status 429;
        }

        location / {
            limit_conn per_ip_conn 50;
        }
    }
}

The values of 5r/s, burst=10, 10 connections, and 50 connections are illustrative syntax. They are not performance guarantees or a recommendation for every application. A login endpoint may need a lower sustained rate, while a busy API may need a higher rate combined with an authenticated-user key.

Understand the leaky-bucket behavior

Nginx’s request module uses the leaky-bucket method. Requests enter a bucket associated with the configured key. The rate determines how quickly that bucket drains; the burst determines how much temporary excess can be queued.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Firewall Appliance 10GbE Mini PC with SFP+, Intel Alder Lake N100 (4C/4T) 4xIntel I226-V 2.5GbE 2*Intel 82599ES 10GbE Firewall LTE Router Support AES-NI (N150, NO RAM NO ROM) (N150, NO RAM NO ROM)
  • 【Professional Firewall & NAS SERVER】OAKNODE 10gbe Firewall Appliance Mini PC-MGNASN, a powerful professional firewall router pc equipped with a 12th Gen Alder Lake N100 4C/4T up to 3.4GHz TDP only 6W with Intel UHD Graphics which maximizes the performance of the 2.5GbE port & SFP+ port, bring you a smooth secured and encrypted network environment.
  • 【Rich I/O to meet your needs】Firewall Appliance MGNASN With HDMI 2.0+DP 1.4+TYPE-C(dp 1.2) Support for 3x4K@60Hz together, Dual DDR4 RAM slot support for up to 1x32GB SO-Dimm laptop DDR5 Ram Maximum 5600Mhz and 1xM.2 NVMe/PCIe 3.0x1 2280 SSD slot +1*SATA 3.0 SSD/HDD slots (install externally), also it support boot from TF card slot and it also support PXE/AWOL/Watchdog/GPIO etc. which is perfect for your firewall appliance、VM、Router、home Server needs.
  • 【2xSFP+ 10GbE + 4x2.5GbE】This Firewall Router equipped with 2xIntel 82599ES 10gbe network card and 4*Intel i226-V network card speed maximum up to 2.5GbE(need other device like router, cables etc. also support 2.5Gbe/10gbe)which can bring you more faster and professional network usage(some system not release drivers yet) suggest to install version of below systems: pf-sense plus 23.0X or CE 2.7.X, OPNsense 22.1, OpenWrt, ROS7, ESXI 8 , Proxmox, CentOS etc).
  • 【4G LTE Function supported】This model also support 4G LTE function(mini PCIE slot for 4G modem) and SIM card slot which you can use it as a IOT devices for your server.
  • 【Quality With Warranty】If you have any questions or requirements(like OS installation/ drives/bios updates etc.) on OAKNODE Firewall mini pc MGNASN, PLEASE feel free to contact us. We offered 12 Months warranty for it and WE'LL REPLY YOUR Questions within 12 hours(during Workdays).
  • With a burst and no nodelay, excess requests can wait in the queue and be released at the configured rate. This protects the upstream application but adds latency.
  • With nodelay, requests within the burst are passed immediately. Once the burst is exhausted, additional requests are rejected instead of waiting.
  • Without enough burst capacity, short legitimate spikes can receive rejections even when the long-term average is acceptable.

Apply the directive to the narrowest location that needs it. A single global IP rate can make a popular page, an API call, and a login attempt compete for the same bucket, producing false positives and leaving expensive paths under-protected.

Choose the response deliberately

Use limit_req_status 429 when clients should understand that they are being throttled and can retry later. Make sure your application and clients handle the response without creating a retry storm. If a particular endpoint requires a different status for compatibility, document that choice and monitor it; do not silently convert every limit event into a generic server error.

Limit simultaneous HTTP connections

Request-rate limiting and connection limiting solve different problems. A client can stay below a requests-per-second threshold while holding many slow or idle connections open. limit_conn_zone creates the key and limit_conn sets the maximum concurrent count.

http {
    limit_conn_zone $binary_remote_addr zone=per_ip_conn:10m;

    server {
        location /api/ {
            limit_conn per_ip_conn 20;
        }

        location /downloads/ {
            limit_conn per_ip_conn 8;
        }
    }
}

Use lower connection ceilings on endpoints that tie up workers, upstream sockets, file descriptors, or expensive application sessions. A static asset location may tolerate a higher value. Keep a broader server-level ceiling as a last-resort safeguard only after verifying that it will not block normal users behind shared networks.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

HTTP/2 and HTTP/3 concurrent requests are counted separately by Nginx’s connection-limiting behavior. Test the policy with the protocols your clients actually use; a browser’s multiplexed traffic does not behave like a collection of unrelated HTTP/1.1 connections.

Restore the real client IP safely

IP-based controls are only as accurate as the key. If Nginx sits behind a load balancer or CDN and sees only the proxy address, all users can fall into one bucket. If it blindly trusts a client-supplied forwarding header, an attacker can put a different address in every request and evade the limit.

Rank #3
Netgate 1100 pfSense+ Security Gateway - Firewall, Router, VPN
  • BUSINESS READY - pfSense+ software updates included for product lifetime. Netgate TAC Lite technical support included. One year hardware warranty included.
  • COMPLETE - Pre-loaded with pfSense+ software to get up and running fast. Simply unbox it and start customizing for your secure edge networking needs. Free help with setup from our expert Technical Assistance Center (TAC) available 24/7/365.
  • POWERFUL - A dual core ARM Cortex-A53 1.2 GHz delivers near gigabit routing of common home iPerf3 traffic and in excess of 650 Mbps of firewall throughput.
  • COMPACT - Low power draw, a compact form factor, and silent operation allow it to run unnoticed when placed on a desktop, wall, or rack.
  • FLEXIBLE - Three (3) 1 GbE switched (WAN/LAN/OPT) ports allow you to configure three separate 1 GbE switched ports for upto a gigabit of bi-directional traffic.

Configure the real-IP module to trust only the documented address ranges of your own load balancers or CDN. Replace the example network below with the complete ranges supplied by that provider, and repeat the directive for every trusted range:

http {
    # Add only proxy or load-balancer CIDRs that you control or explicitly trust.
    set_real_ip_from 192.0.2.0/24;
    real_ip_header X-Forwarded-For;
    real_ip_recursive on;

    limit_req_zone  $binary_remote_addr zone=per_ip_req:10m rate=5r/s;
    limit_conn_zone $binary_remote_addr zone=per_ip_conn:10m;
}

192.0.2.0/24 is a documentation-only example range; it is not a real provider list. Do not copy it as your production trust boundary. Confirm which header your proxy sets, whether it appends or replaces addresses, and whether the final address is validated before enabling recursive processing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

NAT and forward proxies create an unavoidable trade-off: many legitimate people may share one apparent IP. A strict per-IP rule can therefore throttle an office, school, mobile carrier, or public hotspot as if it were one client. Where your application has a trustworthy identity, consider a separate policy keyed by an authenticated account, API credential, or another validated attribute. Never use an attacker-controlled header as a security identity.

Add limits for TCP services in the stream context

HTTP directives do not protect a raw TCP service. For databases, message brokers, mail services, or other stream protocols, define a stream connection zone and enforce a source-keyed limit:

stream {
    limit_conn_zone $binary_remote_addr zone=per_source_stream:10m;

    server {
        listen 12345;
        proxy_pass backend_service;
        limit_conn per_source_stream 10;
    }
}

The port and upstream name in this snippet are examples. Match them to your service and test the limit with legitimate clients before enforcement. Stream connection limits restrict simultaneous sessions; they do not inspect application messages or stop a network flood that prevents the handshake from reaching the server.

Use bandwidth controls as a supporting measure

limit_rate can reduce the download pressure of each connection, which is useful for large responses and selected clients. It is not a substitute for connection limits: an attacker can open many connections and multiply the aggregate bandwidth. Apply bandwidth controls only where the resulting slower response is acceptable, and monitor completion times and upstream resource use.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
VNOPN Fanless Firewall Appliance Intel J3710 4C/4T, Firewall Mini PC, 4 x Intel i226 LAN Ports, Network Gateway, Soft Router, Support PF-Sense/OPN-Sense, AES-NI (8GB RAM 128GB SSD)
  • 【Processor & OS】Firewall Mini PC with Intel J3710 CPU up to 2.64GHz, 4Cores 4threads 2MB L2 Cache, TDP 6.5w, supports AES-NI. It tested with pf-sens/opn-sense linux ubuntu and other popular open source os. ("DEL" key to enter BIOS)
  • 【Interfaces】The firewall pc has 4 * Intel I226 lan ports, 2 * USB3.0 ports, 1 * RS232COM port, 2 * HD port, 1 * DC port. Equipped with VESA mount, you can install the micro pc behind the monitor to save space.
  • 【Fanless Design】only 6.5W; fanless heat dissipation design, aluminum alloy shell, efficient and fast heat dissipation, which can withstand temperatures up to 60°C. support 24/7 hours working, no noise.
  • 【RAM & Storage】The firewall router equipped with 8G DDR3 RAM, max support 8GB; 128GB mSATA SSD, up to 512GB. Not support HDD. Size:5.27 * 4.98 * 1.43 inches, Weigh:500g, small but powerful.
  • 【12 Months Service】You will get a firewall pc and accessories,If you encounter any problems during the use, please contact us through Amazon, we have a professional and efficient team dedicated to serving you.

Roll out in dry-run mode

Changing from unlimited traffic to hard rejection in one step can lock out legitimate users. A staged rollout exposes the would-be decisions without enforcing them.

  1. Establish the baseline. Capture request rates, concurrency, latency, upstream queueing, and status-code rates for each protected endpoint during normal peaks.
  2. Add the zones and policies. Start with the expensive or abuse-prone locations rather than the entire site.
  3. Enable observation. Set limit_req_dry_run on; while you inspect Nginx logs and your metrics for requests that would have been delayed or rejected. Dry-run records the policy’s decisions but does not impose the limit.
  4. Check shared-network effects. Identify whether would-be events cluster around a corporate NAT, carrier network, monitoring service, or legitimate API client.
  5. Enforce intentionally. Remove or disable dry-run for the selected location, retain an explicit status such as 429, and reload only after nginx -t succeeds.
  6. Review after deployment. Watch latency, upstream queueing, 4xx and 5xx rates, connection counts, and support reports. Adjust the affected endpoint instead of loosening every limit globally.

A typical validation sequence is:

nginx -t
nginx -s reload

Use the service manager’s reload command instead when that is how your installation is operated. A successful syntax test does not prove that the thresholds are appropriate; traffic observation remains necessary.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Tune limits without creating a self-inflicted outage

Set the sustained rate from measured peaks

Use a baseline that includes legitimate bursts, not a quiet five-minute average. Separate endpoints with different costs. For example, a password-reset request that triggers email delivery should not share the same allowance as a cached health check. Start conservatively in dry-run mode, then raise or lower the rate based on observed legitimate demand and upstream capacity.

Size the burst for short spikes

A burst absorbs a brief queue; it does not increase the sustainable rate. A large burst can let an attacker create a sudden workload before the bucket drains, while a tiny burst can reject normal browser refreshes or a page’s parallel API calls. Choose it with the endpoint’s request pattern and acceptable latency in mind.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use connection ceilings for slow clients

Rate limits count requests, not necessarily the resources held by slow connections. Pair request limits with a connection ceiling on endpoints vulnerable to idle sessions, long uploads, or expensive streaming responses. Verify file-descriptor, worker, and upstream-socket usage while testing.

Account for protocol and identity changes

Test HTTP/1.1, HTTP/2, and HTTP/3 where enabled. Recheck the key after every proxy or load-balancer change. A deployment that suddenly makes every user appear under one address can turn a correct policy into a site-wide denial of service.

Best Value
Firewall Mini PC, Intel J1900 4-Port i210 Router, 4GB RAM 64GB SSD
  • 【CPU Optimized for Firewall Mini PCs】This firewall appliance is powered by Intel Quad-Core Celeron J1900, 64-bit, up to 2.0 GHz, supporting software-based encryption. Energy-efficient and reliable, it runs 24/7 for home or small office networks, handling VPNs, multi-WAN routing, and basic firewall tasks efficiently.
  • 【4×Intel i210 Ports】Equipped with four Intel i210 network controllers, each delivering up to 1 GbE for reliable multi-WAN routing, VPN connections, VLAN management, and stable performance in small office or home firewall deployments
  • 【Memory & Storage】This Firewall Mini PC comes with 4 GB DDR3L RAM and a 64 GB mSATA SSD, providing reliable performance for basic networking tasks. AMI BIOS with ACPI support ensures stable system operation and energy-efficient 24/7 use
  • 【Flexible System Compatibility】Compatible with Windows 10, Linux, and professional firewall systems such as pfSense, OPNsense, and VyOS, ensuring stable network management for home or small office use
  • 【After-Sales Support:】This compact, fanless, and silent firewall keeps your network secure. Includes lifetime technical support and a 30-day money-back guarantee!

Respond when an attack is underway

  • Confirm whether the event is application-layer (high request volume, repeated URLs, expensive methods) or volumetric (the access link or provider edge is saturated).
  • For application-layer pressure, tighten only the affected locations, reduce connection ceilings, and preserve access for health checks and administrative paths through a separately trusted route.
  • For a volumetric event, contact the upstream network, CDN, or scrubbing provider immediately. Nginx cannot process packets that never reach the host.
  • Keep evidence: timestamps, source distributions, requested paths, protocol versions, status codes, latency, and upstream saturation. This helps the provider filter accurately and helps you tune permanent policies.
  • After traffic subsides, review false positives and restore normal thresholds deliberately rather than leaving emergency settings in place.

When to place a CDN or scrubbing service in front

An upstream service is warranted when attacks can exceed the origin’s link, firewall capacity, or provider limits; when you need globally distributed absorption; or when the application requires detection beyond simple IP and connection counters. The origin should accept traffic only from the upstream service’s published ranges where that design is practical. Otherwise an attacker can bypass the edge and target the origin directly.

Keep Nginx limits even behind an upstream service. Edge filtering reduces the volume that reaches the origin, while Nginx still protects individual endpoints and upstream workers from abusive requests that pass the edge’s broader policy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Enterprise application-layer option

F5 NGINX App Protect DoS is a separate, licensed product rather than an open-source Nginx directive. Its policy documentation describes standard, conservative, and none mitigation modes, along with signatures, bad-actor detection, automation-tool detection, and TLS fingerprinting. Treat deployment, licensing, policy tuning, and failure behavior as an architecture review; do not assume those features exist in the open-source package.

Troubleshooting common failures

Everyone receives 429 responses

Check the key first. If a proxy address is being used for every request, restore the real IP from trusted proxy ranges. If many users genuinely share a NAT address, lower the per-IP strictness or use an authenticated identity for the endpoint. Confirm that a broad server or inherited location policy is not consuming the same bucket.

The limit appears ineffective

Verify that the request reaches the location containing limit_req or limit_conn, that the zone is declared in the correct context, and that Nginx was successfully reloaded. Check whether the attacker is distributing traffic across many addresses, using a different hostname or protocol, or bypassing the proxy and reaching the origin directly.

Legitimate bursts are delayed

Use dry-run logs to identify the exact endpoint and client population. Increase the burst or sustained rate only for that location, or create a separate policy for trusted authenticated traffic. Do not remove all limits because one shared network was misclassified.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Nginx remains healthy but the site is unreachable

Inspect the host’s interface, firewall, and upstream link. If those are saturated, local Nginx metrics may look normal because traffic cannot reach the worker. Escalate to the network or scrubbing provider; application-layer tuning cannot clear a full access link.

Operational checklist

  • Use a trusted, validated client identity for every key.
  • Define request and connection zones at http scope and stream zones at stream scope.
  • Protect expensive endpoints before applying broad site-wide limits.
  • Start with limit_req_dry_run on; and review logs and metrics.
  • Return an intentional 429 response for rejected HTTP requests.
  • Pair request rates with concurrent-connection ceilings where slow or multiplexed connections matter.
  • Remember that HTTP/2 and HTTP/3 concurrency is counted separately.
  • Use bandwidth limits only as a supplement to connection limits.
  • Keep the origin restricted behind the upstream edge where possible.
  • Escalate volumetric attacks that saturate the link; Nginx cannot replace upstream scrubbing.