How a web server allocates connections
accept() to pull that socket out of the kernel queue and assign it to a worker. What "worker" means depends on the server architecture:
- Apache prefork MPM spawns a separate process per connection. Each process handles one request at a time. The
MaxRequestWorkersdirective (historicallyMaxClients) caps how many simultaneous connections Apache will serve. A common default is 256. - Apache worker/event MPM uses threads instead of full processes, so the ceiling is higher, but there is still a finite
MaxRequestWorkerslimit. - Nginx uses an event-driven loop. A single worker process can handle thousands of connections concurrently because it never blocks on a single socket. But even Nginx has a
worker_connectionslimit per worker process. - LiteSpeed uses an event-driven architecture similar to Nginx, with its own connection pool limits.
net.core.somaxconn and the listen backlog parameter) or get refused outright.
What Slowloris actually does at the socket level
- The attacker opens a TCP connection and sends the beginning of an HTTP request — typically just the request line and a few headers.
- Crucially, the attacker never sends the final blank line (
\\r\ \\r\) that signals the end of the HTTP headers. The request stays incomplete. - The web server has accepted the connection and allocated a worker to it. That worker is now waiting for the rest of the headers. It cannot serve anyone else while it waits.
- Periodically — every few seconds — the attacker sends another partial header line (like
X-Whatever: keep-alive\\r\). This resets any read timeout the server might have, keeping the connection alive without completing the request. - The attacker repeats this across hundreds or thousands of connections simultaneously.
Why bandwidth monitoring misses it
BASH
# Count connections per state
ss -s
# Count established connections to port 80 or 443 grouped by source IP
ss -tn state established '( dport = :80 or dport = :443 )' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -20TEXT
847 203.0.113.45
612 198.51.100.12
3 192.0.2.77
2 192.0.2.50
1 192.0.2.33Detection beyond connection counts
server-status page (if enabled) shows each worker's state. During a Slowloris attack, you will see a large number of workers stuck in the "R" (reading request) state for abnormally long durations. Normally, reading a request header takes milliseconds. If workers have been in "R" state for 30, 60, 120 seconds, something is wrong.
For Nginx, the stub_status module exposes Active connections, Reading, Writing, and Waiting counts. A sudden jump in Reading with flat Writing is the same signal.
Another angle: check your access log. Slowloris connections that never complete a request never generate an access log entry. If your connection count is high but your request rate in the access log is flat or dropping, incomplete requests are consuming your workers.
Mitigation at the web server level
mod_reqtimeout (included by default in builds since around Apache 2.2.15). A reasonable configuration:
APACHE
# Require the full header within 20 seconds,
# granting 500ms extra per 500 bytes received.
# Require the full body within 30 seconds,
# granting 1 second extra per 1000 bytes received.
RequestReadTimeout header=20-40,MinRate=500 body=30-60,MinRate=1000MinRate parameter extends the deadline proportionally to data actually received.
Nginx handles this differently because of its event-driven model. Nginx is inherently more resistant to Slowloris since a slow connection does not block a worker process. However, it still consumes a connection slot and kernel memory. Relevant directives:
client_header_timeout— how long Nginx waits for the complete request header. Default is typically 60 seconds; lowering it to 10-20 seconds is reasonable.client_body_timeout— same concept for the request body.limit_connmodule — caps how many simultaneous connections a single IP can hold.
limit_conn_zone and limit_conn handle it. In Apache, mod_limitipconn or firewall rules (iptables/nftables connlimit match) achieve the same thing. A limit of 20-50 concurrent connections per IP is reasonable for most sites; adjust based on your traffic patterns.
Switch from prefork to event MPM (Apache). If you are still running Apache with the prefork MPM, you are maximally vulnerable to Slowloris because every connection pins an entire process. The event MPM handles keep-alive and idle connections in a dedicated listener thread, freeing worker threads for active requests. This does not eliminate the vulnerability, but it raises the bar significantly.
Use a reverse proxy. Placing Nginx or HAProxy in front of Apache is a common pattern. The reverse proxy absorbs slow connections with its event-driven architecture, only forwarding complete requests to Apache. Apache workers never see the slow client and never get pinned.
The broader category: slow HTTP attacks
- Slow POST (R.U.D.Y.) — sends the request headers normally, declares a large
Content-Length, then trickles the body one byte at a time. The server waits for the full body before processing. - Slow read — sends a complete request but reads the response extremely slowly, or sets a tiny TCP receive window, forcing the server to keep the connection and response buffer open.
What to actually do
mod_reqtimeout or equivalent header/body timeouts on every web server you manage. Limit concurrent connections per source IP at the web server or firewall level. If you run Apache prefork, seriously consider switching to the event MPM or fronting it with an event-driven reverse proxy. These are not exotic hardening steps — they are baseline configuration for any internet-facing web server. The attack tool is trivial to run, and the fix is configuration, not hardware.