The PHP-FPM pool maxes out at 200 children. A coordinated brute force hits /wp-login.php at 30 requests per second from a botnet that rotates through 4,000 residential IPs. Cloudflare’s managed WAF passes the requests through — each one looks like a single login attempt from a clean IP. nginx happily proxies them. PHP-FPM saturates within 90 seconds. The site is down, not because the brute force is succeeding, but because the brute force is doing free DDoS as a side effect.
What’s happening
WordPress brute-force protection at the plugin layer (Wordfence, Limit Login Attempts) is reactive — it sees an attempt only after PHP has bootstrapped, the request has hit the database, and a counter has been incremented. At 200 child processes and 8 seconds per wp-login.php cold cycle, the pool exhausts long before the plugin reaches its threshold.
Rate limiting belongs upstream of PHP. The defensible layering looks like this:
- Cloudflare rate-limiting rule drops or challenges traffic above a per-IP threshold at the edge. Stops the cheap floods, costs nothing in origin resources.
- nginx
limit_reqenforces a second threshold at the origin for traffic that came through Cloudflare or bypassed it. Protects PHP-FPM regardless of edge state. - fail2ban scans nginx access logs for elevated 401/403/429 patterns and adds offending IPs to an iptables/ipset deny list — a sticky penalty after the rate limit has already kicked in.
The three layers do different things and shouldn’t be conflated. Cloudflare is cheap and global but only protects what comes through Cloudflare. nginx is universal but only sees per-process traffic. fail2ban is sticky but slow to react. Together they handle the cases each one alone can’t.
How to verify
Confirm what’s getting through at each layer.
# How many wp-login.php POSTs per minute right now?
tail -n 100000 /var/log/nginx/access.log \
| awk '$7 == "/wp-login.php" && $9 == "200"' \
| awk '{print $4}' | cut -c14-18 | sort | uniq -c | tail -10
# Are they all from one IP or distributed?
awk '$7 == "/wp-login.php"' /var/log/nginx/access.log \
| awk '{print $1}' | sort | uniq -c | sort -rn | head -20
If the per-minute count is rising and the IP distribution is wide (4 requests per IP across hundreds of IPs in 5 minutes), this is a slow distributed brute force — exactly the case where plugin-layer counters fail.
For xmlrpc:
awk '$7 ~ /xmlrpc/' /var/log/nginx/access.log \
| awk '{print $9}' | sort | uniq -c
# Mostly 200s? xmlrpc is open and being hit.
For the REST API:
awk '$7 ~ "/wp-json/wp/v2/users"' /var/log/nginx/access.log \
| awk '{print $1, $9}' | sort | uniq -c | sort -rn | head -20
The fix
Layer 1: Cloudflare rate-limiting rule
# Rate limit wp-login.php POSTs to 5/min per IP, challenge above
curl -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE}/rulesets/phases/http_ratelimit/entrypoint/rules" \
-H "Authorization: Bearer ${CF_TOKEN}" -H "Content-Type: application/json" -d '{
"description": "wp-login.php POST rate limit",
"expression": "(http.request.uri.path eq \"/wp-login.php\" and http.request.method eq \"POST\")",
"action": "managed_challenge",
"ratelimit": {
"characteristics": ["ip.src", "cf.colo.id"],
"period": 60,
"requests_per_period": 5,
"mitigation_timeout": 600
}
}'
# Rate limit /wp-json/ to 30/min per IP
curl -X POST "https://api.cloudflare.com/client/v4/zones/${ZONE}/rulesets/phases/http_ratelimit/entrypoint/rules" \
-H "Authorization: Bearer ${CF_TOKEN}" -H "Content-Type: application/json" -d '{
"description": "REST API rate limit",
"expression": "(http.request.uri.path starts_with \"/wp-json/\" and not http.request.headers[\"x-wp-nonce\"][0] ne \"\")",
"action": "block",
"ratelimit": {
"characteristics": ["ip.src"],
"period": 60,
"requests_per_period": 30,
"mitigation_timeout": 60
}
}'
mitigation_timeout is the sticky period — once a client crosses the threshold, the action persists for that many seconds even if they slow down. Ten minutes for login attempts is appropriate; a single minute for REST is enough to break tooling without locking out real users.
Layer 2: nginx limit_req
# /etc/nginx/conf.d/wordpress-rate-limits.conf
# Per-IP zones. binary_remote_addr is 4 bytes IPv4 / 16 IPv6.
limit_req_zone $binary_remote_addr zone=wp_login:10m rate=10r/m;
limit_req_zone $binary_remote_addr zone=wp_xmlrpc:10m rate=5r/m;
limit_req_zone $binary_remote_addr zone=wp_rest:10m rate=60r/m;
limit_req_zone $binary_remote_addr zone=wp_admin:10m rate=120r/m;
# 10m holds ~160,000 unique IPs of state — plenty for one origin.
server {
listen 443 ssl http2;
server_name example.com;
# Trust Cloudflare's CF-Connecting-IP, but only from Cloudflare's ranges
# (set_real_ip_from blocks configured elsewhere)
location = /wp-login.php {
limit_req zone=wp_login burst=5 nodelay;
limit_req_status 429;
limit_req_log_level warn;
include /etc/nginx/snippets/php-fpm.conf;
}
location = /xmlrpc.php {
# If you don't need xmlrpc, just return 403 here.
# If you do, limit aggressively.
limit_req zone=wp_xmlrpc burst=2 nodelay;
limit_req_status 429;
include /etc/nginx/snippets/php-fpm.conf;
}
location ^~ /wp-json/ {
limit_req zone=wp_rest burst=20 nodelay;
limit_req_status 429;
include /etc/nginx/snippets/php-fpm.conf;
}
location ^~ /wp-admin/ {
limit_req zone=wp_admin burst=40 nodelay;
limit_req_status 429;
include /etc/nginx/snippets/php-fpm.conf;
}
location ~ \.php$ {
include /etc/nginx/snippets/php-fpm.conf;
}
}
burst=N nodelay means: allow up to N excess requests to queue without delay, after which return 429. nodelay matters — without it, requests above the rate get queued and tie up nginx worker connections, defeating the protective purpose.
nginx -t && systemctl reload nginx
# Watch the limit fire
tail -F /var/log/nginx/error.log | grep "limiting requests"
Layer 3: fail2ban
fail2ban catches the IPs that learned to stay just under the nginx threshold but kept trying.
# /etc/fail2ban/jail.d/wordpress.conf
[nginx-wp-login]
enabled = true
filter = nginx-wp-login
logpath = /var/log/nginx/access.log
port = http,https
maxretry = 10
findtime = 600
bantime = 86400
action = iptables-multiport[name=wp-login, port="http,https"]
[nginx-wp-xmlrpc]
enabled = true
filter = nginx-wp-xmlrpc
logpath = /var/log/nginx/access.log
port = http,https
maxretry = 3
findtime = 300
bantime = 86400
[nginx-wp-429]
enabled = true
filter = nginx-wp-429
logpath = /var/log/nginx/access.log
maxretry = 20
findtime = 600
bantime = 3600
The filter definitions:
# /etc/fail2ban/filter.d/nginx-wp-login.conf
[Definition]
failregex = ^<HOST> .* "POST /wp-login\.php HTTP.*" (401|403) .*$
ignoreregex =
# /etc/fail2ban/filter.d/nginx-wp-xmlrpc.conf
[Definition]
failregex = ^<HOST> .* "(POST|GET) /xmlrpc\.php HTTP.*" .*$
ignoreregex =
# /etc/fail2ban/filter.d/nginx-wp-429.conf
[Definition]
failregex = ^<HOST> .* "(GET|POST) .* HTTP.*" 429 .*$
ignoreregex =
The nginx-wp-429 jail is the important one — it captures everyone who tripped the nginx rate limit and gives them a sticky one-hour ban, so they stop adding noise to the access log.
fail2ban-client reload
fail2ban-client status nginx-wp-login
# Currently failed / banned
fail2ban-client status nginx-wp-429
Real-client-IP under Cloudflare
If you’re terminating Cloudflare in front of nginx, fail2ban will ban the Cloudflare edge IPs unless nginx logs the real client IP and your filter regex matches the position where that IP lands in the log line. Set set_real_ip_from to Cloudflare’s ranges and real_ip_header CF-Connecting-IP — and update the fail2ban filter’s <HOST> regex to read the same field nginx is now logging.
Verifying the layering works
Run a small synthetic test from an isolated IP:
# Burst 20 POSTs in 10 seconds to wp-login.php
for i in $(seq 1 20); do
curl -o /dev/null -s -w "%{http_code}\n" -X POST \
"https://example.com/wp-login.php" -d "log=fake&pwd=fake"
done
Expected: first 5 return 200/302, next handful return 429 (nginx), then Cloudflare picks up and serves a challenge or 403. After 10 minutes the test IP appears in fail2ban-client status nginx-wp-login.
Stack Harbor configures this layered rate-limiting on every site we operate under managed enterprise WordPress hosting, including the fail2ban jails and the Cloudflare ratelimit rules in version control. For the broader origin side — including PHP-FPM sizing that absorbs the slow leaks fail2ban hasn’t yet caught — environment management covers it. Tell us what you’re seeing.