<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bruce</title>
    <description>The latest articles on DEV Community by Bruce (@brownieee).</description>
    <link>https://dev.to/brownieee</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4281233%2F2d340c52-6b00-4a50-bd2e-dd6f69d642e7.png</url>
      <title>DEV Community: Bruce</title>
      <link>https://dev.to/brownieee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brownieee"/>
    <language>en</language>
    <item>
      <title>I DDoS'd My Own Nginx Server. Raising the Limits Made It Worse.</title>
      <dc:creator>Bruce</dc:creator>
      <pubDate>Thu, 03 Dec 2026 18:37:52 +0000</pubDate>
      <link>https://dev.to/brownieee/i-ddosd-my-own-nginx-server-raising-the-limits-made-it-worse-km6</link>
      <guid>https://dev.to/brownieee/i-ddosd-my-own-nginx-server-raising-the-limits-made-it-worse-km6</guid>
      <description>&lt;p&gt;The Setup&lt;br&gt;
Parrot OS, Nginx installed via apt, default config. No rate limiting. No connection caps. No CDN. Just a web server on localhost.&lt;/p&gt;

&lt;p&gt;$ curl &lt;a href="http://localhost" rel="noopener noreferrer"&gt;http://localhost&lt;/a&gt;&lt;br&gt;
Welcome to nginx!&lt;/p&gt;

&lt;p&gt;The "attacker" is hey (Go-based load tester) on the same machine:&lt;/p&gt;

&lt;p&gt;hey -n 50000 -c 10000 -disable-keepalive &lt;a href="http://localhost/" rel="noopener noreferrer"&gt;http://localhost/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;50,000 total requests, 10,000 concurrent connections, no keepalive (every request = new TCP connection). This is a load test, not a DDoS. But the failure mode is identical to what a real flood does to a misconfigured server.&lt;/p&gt;

&lt;p&gt;The "vulnerability" is the default file descriptor limit:&lt;/p&gt;

&lt;p&gt;$ ulimit -n&lt;br&gt;
1024&lt;/p&gt;

&lt;p&gt;Default Nginx on Debian/Parrot ships with:&lt;/p&gt;

&lt;p&gt;Setting Value&lt;br&gt;
worker_processes    auto (4 workers)&lt;br&gt;
worker_connections  512 (default)&lt;br&gt;
limit_req   not set&lt;br&gt;
limit_conn  not set&lt;br&gt;
ulimit -n   1024&lt;br&gt;
net.core.somaxconn  4096&lt;br&gt;
net.ipv4.tcp_max_syn_backlog    512&lt;/p&gt;

&lt;p&gt;Act 1: The Bare Server Dies Silently&lt;br&gt;
I ran the test. Here's what hey reported:&lt;/p&gt;

&lt;p&gt;$ hey -n 50000 -c 10000 -disable-keepalive &lt;a href="http://localhost/" rel="noopener noreferrer"&gt;http://localhost/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Summary:&lt;br&gt;
  Total:        5.6736 secs&lt;br&gt;
  Slowest:      3.1000 secs&lt;br&gt;
  Fastest:      0.0251 secs&lt;br&gt;
  Average:      1.0043 secs&lt;br&gt;
  Requests/sec: 8812.6858&lt;/p&gt;

&lt;p&gt;Status code distribution:&lt;br&gt;
  [200] 8784 responses&lt;/p&gt;

&lt;p&gt;Error distribution:&lt;br&gt;
  [39935]  Get "&lt;a href="http://localhost/%22:" rel="noopener noreferrer"&gt;http://localhost/":&lt;/a&gt; EOF&lt;br&gt;
  [1281]   Get "&lt;a href="http://localhost/%22:" rel="noopener noreferrer"&gt;http://localhost/":&lt;/a&gt; http: server closed idle connection&lt;/p&gt;

&lt;p&gt;80% of my requests never got a response. Not a 503. Not a 502. Not even a TCP RST the client could interpret. Just... EOF. The connection opened, and then nothing came back.&lt;/p&gt;

&lt;p&gt;I checked the Nginx error log:&lt;/p&gt;

&lt;p&gt;$ tail -f /var/log/nginx/error.log&lt;/p&gt;

&lt;p&gt;Empty. Zero entries. Nginx had no idea it was losing connections.&lt;/p&gt;

&lt;p&gt;I checked the kernel:&lt;/p&gt;

&lt;p&gt;$ netstat -s | grep -i "reset|drop"&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;880 connection resets received
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;10135 resets sent&lt;br&gt;
    2201 connections reset due to unexpected data&lt;br&gt;
     562 connections reset due to early user close&lt;/p&gt;

&lt;p&gt;10,135 resets sent by the kernel. The TCP stack was dropping SYNs and sending RSTs before Nginx ever called accept(). The tcp_max_syn_backlog of 512 overflowed almost instantly under 10,000 concurrent connections.&lt;/p&gt;

&lt;p&gt;From the user's perspective: their browser shows "Connection Reset" or just hangs. No error page. No status code. The sysadmin checking Nginx logs finds nothing.&lt;/p&gt;

&lt;p&gt;Act 2: I Raised the Limits. It Got Worse.&lt;br&gt;
The obvious "fix" is to raise everything:&lt;/p&gt;

&lt;h1&gt;
  
  
  Kernel: allow more pending SYNs
&lt;/h1&gt;

&lt;p&gt;sudo sysctl -w net.core.somaxconn=65535&lt;br&gt;
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=65535&lt;/p&gt;

&lt;h1&gt;
  
  
  Nginx: allow more file descriptors
&lt;/h1&gt;

&lt;h1&gt;
  
  
  /etc/systemd/system/nginx.service.d/override.conf
&lt;/h1&gt;

&lt;p&gt;[Service]&lt;br&gt;
LimitNOFILE=65535&lt;br&gt;
LimitNOFILESoft=65535&lt;/p&gt;

&lt;h1&gt;
  
  
  Nginx: raise listen backlog
&lt;/h1&gt;

&lt;h1&gt;
  
  
  listen 80 backlog=65535;
&lt;/h1&gt;

&lt;p&gt;I applied all of it. Verified:&lt;/p&gt;

&lt;p&gt;$ systemctl show nginx | grep LimitNOFILE&lt;br&gt;
LimitNOFILE=65535&lt;br&gt;
LimitNOFILESoft=65535&lt;/p&gt;

&lt;p&gt;$ sysctl net.core.somaxconn&lt;br&gt;
net.core.somaxconn = 65535&lt;/p&gt;

&lt;p&gt;Re-ran the exact same test:&lt;/p&gt;

&lt;p&gt;$ hey -n 50000 -c 10000 -disable-keepalive &lt;a href="http://localhost/" rel="noopener noreferrer"&gt;http://localhost/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Summary:&lt;br&gt;
  Total:        5.5822 secs&lt;br&gt;
  Slowest:      1.4389 secs&lt;br&gt;
  Fastest:      0.0146 secs&lt;br&gt;
  Average:      0.4700 secs&lt;br&gt;
  Requests/sec: 8956.9952&lt;/p&gt;

&lt;p&gt;Status code distribution:&lt;br&gt;
  [200] 5520 responses&lt;/p&gt;

&lt;p&gt;Error distribution:&lt;br&gt;
  [42933]  Get "&lt;a href="http://localhost/%22:" rel="noopener noreferrer"&gt;http://localhost/":&lt;/a&gt; EOF&lt;br&gt;
  [1547]   Get "&lt;a href="http://localhost/%22:" rel="noopener noreferrer"&gt;http://localhost/":&lt;/a&gt; http: server closed idle connection&lt;/p&gt;

&lt;p&gt;86% dead. Up from 80%.&lt;/p&gt;

&lt;p&gt;I went from 8,784 successful responses to 5,520. The "fix" made things 1.6x worse.&lt;/p&gt;

&lt;p&gt;Why Raising Limits Made It Worse&lt;br&gt;
This is the counterintuitive part, and it's the whole point of this article.&lt;/p&gt;

&lt;p&gt;When somaxconn is 4096, the kernel's accept queue holds at most 4,096 completed handshakes. Once it's full, the kernel drops new SYNs immediately. The client retries a few times, gives up, and you get an EOF. The failure is fast and bounded.&lt;/p&gt;

&lt;p&gt;When somaxconn is 65,535, the accept queue can hold 65,535 completed handshakes. Now the kernel accepts every SYN and queues the connection. But Nginx's workers can only accept() so fast. The queue grows to thousands of pending connections. The kernel's TCP stack starts timing out individual connections in the queue, sending RSTs in bulk. You get more EOFs because the failure is now delayed and cascading instead of fast and clean.&lt;/p&gt;

&lt;p&gt;A bigger bucket doesn't help if the drain is the same size. You just let more water in before it overflows, and the overflow is messier.&lt;/p&gt;

&lt;p&gt;Act 3: Rate Limiting (Partial Improvement)&lt;br&gt;
The real defense isn't more capacity. It's rejecting the flood early so it never reaches the accept queue:&lt;/p&gt;

&lt;h1&gt;
  
  
  /etc/nginx/nginx.conf, inside http { }
&lt;/h1&gt;

&lt;p&gt;limit_req_zone $binary_remote_addr zone=flood:10m rate=100r/s;&lt;br&gt;
limit_conn_zone $binary_remote_addr zone=conn:10m;&lt;br&gt;
limit_req_status 429;&lt;br&gt;
limit_conn_status 429;&lt;/p&gt;

&lt;h1&gt;
  
  
  server { } block
&lt;/h1&gt;

&lt;p&gt;location / {&lt;br&gt;
    limit_req zone=flood burst=100 nodelay;&lt;br&gt;
    limit_conn conn 100;&lt;br&gt;
    return 200 "OK\n";&lt;br&gt;
    add_header Content-Type text/plain;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;Re-ran the same test:&lt;/p&gt;

&lt;p&gt;$ hey -n 50000 -c 10000 -disable-keepalive &lt;a href="http://localhost/" rel="noopener noreferrer"&gt;http://localhost/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Summary:&lt;br&gt;
  Total:        5.9076 secs&lt;br&gt;
  Slowest:      2.5803 secs&lt;br&gt;
  Fastest:      0.0011 secs&lt;br&gt;
  Average:      0.9384 secs&lt;br&gt;
  Requests/sec: 8463.7342&lt;/p&gt;

&lt;p&gt;Status code distribution:&lt;br&gt;
  [200] 12976 responses&lt;/p&gt;

&lt;p&gt;Error distribution:&lt;br&gt;
  [36029]  Get "&lt;a href="http://localhost/%22:" rel="noopener noreferrer"&gt;http://localhost/":&lt;/a&gt; EOF&lt;br&gt;
  [994]    Get "&lt;a href="http://localhost/%22:" rel="noopener noreferrer"&gt;http://localhost/":&lt;/a&gt; http: server closed idle connection&lt;br&gt;
  [1]      Get "&lt;a href="http://localhost/%22:" rel="noopener noreferrer"&gt;http://localhost/":&lt;/a&gt; read tcp 127.0.0.1:56156-&amp;gt;127.0.0.1:80:&lt;br&gt;
           read: connection reset by peer&lt;/p&gt;

&lt;p&gt;Still 72% dead. But two things changed:&lt;/p&gt;

&lt;p&gt;12,976 got through (up from 5,520 with raised limits alone). The rate limiter is doing its job. It's letting legitimate traffic through while blocking the flood.&lt;br&gt;
That single connection reset by peer is the first time Nginx is actively acknowledging the attack. It's not silent anymore.&lt;br&gt;
Why It's Not 100% Yet&lt;br&gt;
Rate limiting alone can't save a single VPS from 10,000 concurrent connections. In production, you'd layer:&lt;/p&gt;

&lt;p&gt;CDN in front (Cloudflare free tier) to absorb volumetric floods before they reach your server&lt;br&gt;
limit_req + limit_conn to reject excess at the app layer&lt;br&gt;
Kernel tuning for somaxconn + tcp_max_syn_backlog (but NOT to 65535. 4096 is fine)&lt;br&gt;
Monitoring to alert when EOF rate &amp;gt; 5% or netstat -s resets spike&lt;br&gt;
The rate limiter is one layer, not the whole defense.&lt;/p&gt;

&lt;p&gt;The Results&lt;br&gt;
Approach    200s    EOFs    % Dead  User Sees   Sysadmin Sees&lt;br&gt;
Bare Nginx (default)    8,784   39,935  80% "Connection Reset" / hang   Nothing in logs&lt;br&gt;
Raised limits (somaxconn=65535) 5,520   42,933  86% "Connection Reset" / hang   Nothing in logs&lt;br&gt;
Rate limiting + raised limits   12,976  36,029  72% "Connection Reset" / hang   1 RST in logs&lt;/p&gt;

&lt;p&gt;Three Takeaways&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;The kernel is your first line of defense, and it fails silently. tcp_max_syn_backlog overflow doesn't log to Nginx. When you see unexplained connection failures, check netstat -s | grep "resets sent" before blaming the app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Raising limits is not a security fix. It's a capacity fix. A bigger accept queue under flood = more queued connections = worse cascading failures. You need to reduce the load, not increase the bucket.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;limit_req + limit_conn are your actual first defense. They're two lines of config. They turn a silent death into at least a server that acknowledges the attack. Every production Nginx server should have them. If yours doesn't, add them today.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Reproduce This&lt;/p&gt;

&lt;h1&gt;
  
  
  Install (Parrot/Debian/Ubuntu)
&lt;/h1&gt;

&lt;p&gt;sudo apt install nginx&lt;br&gt;
go install github.com/rakyll/hey@latest&lt;/p&gt;

&lt;h1&gt;
  
  
  Start
&lt;/h1&gt;

&lt;p&gt;sudo systemctl start nginx&lt;/p&gt;

&lt;h1&gt;
  
  
  Kill it
&lt;/h1&gt;

&lt;p&gt;hey -n 50000 -c 10000 -disable-keepalive &lt;a href="http://localhost/" rel="noopener noreferrer"&gt;http://localhost/&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Check the damage
&lt;/h1&gt;

&lt;p&gt;netstat -s | grep "resets sent"&lt;/p&gt;

&lt;h1&gt;
  
  
  The "fix" that makes it worse
&lt;/h1&gt;

&lt;p&gt;sudo sysctl -w net.core.somaxconn=65535&lt;/p&gt;

&lt;h1&gt;
  
  
  Add LimitNOFILE=65535 to systemd override
&lt;/h1&gt;

&lt;p&gt;sudo systemctl daemon-reload &amp;amp;&amp;amp; sudo systemctl restart nginx&lt;br&gt;
hey -n 50000 -c 10000 -disable-keepalive &lt;a href="http://localhost/" rel="noopener noreferrer"&gt;http://localhost/&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Worse. 86% dead.
&lt;/h1&gt;

&lt;h1&gt;
  
  
  The actual fix
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Add limit_req + limit_conn to nginx config
&lt;/h1&gt;

&lt;p&gt;sudo systemctl restart nginx&lt;br&gt;
hey -n 50000 -c 10000 -disable-keepalive &lt;a href="http://localhost/" rel="noopener noreferrer"&gt;http://localhost/&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Better. Server acknowledges the flood.
&lt;/h1&gt;

</description>
      <category>nginx</category>
      <category>linux</category>
      <category>security</category>
      <category>ddos</category>
    </item>
  </channel>
</rss>
