How to Limit WordPress Login Attempts Without a Plugin

How to Limit WordPress Login Attempts Without a Plugin

To limit WordPress login attempts without a plugin, put the limit on the server instead of inside WordPress. Nginx can slow repeated requests to wp-login.php, Fail2ban can block an IP that keeps guessing passwords, and Cloudflare can stop the traffic before it reaches your VPS. You need SSH access and a WordPress site on Nginx.

Plugins that limit logins run inside WordPress, so every bad attempt still loads PHP and hits the database before the plugin says no. A server-level limit stops the request earlier and costs far less CPU, which matters on a small VPS.

Why wp-login.php Gets Hit So Often

Every WordPress install has the same login URL, and every bot knows it. Automated scanners look for /wp-login.php, then try common usernames such as admin and passwords from leaked lists. A fresh install can see its first login attempts within hours of going live. Most of them fail, but each one still costs your server a PHP request.

A real user types a password wrong once or twice and moves on. A bot tries hundreds of combinations in a minute. A rate limit draws the line between those two patterns. For a wider look at what attackers try first, read our guide on how to protect your WordPress login page from brute force attacks.

Method 1: Limit WordPress Login Attempts with Nginx Rate Limiting

Nginx rate limiting is the first layer, and for most sites it is enough on its own. It caps how many requests one IP can send to the login page, and answers the extra requests with an error instead of passing them to PHP.

Add a shared memory zone in the http block of your Nginx site config, usually in /etc/nginx/sites-available/ or /etc/nginx/conf.d/:

http {
    limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
    ...
}

This allows one request per second per IP on average, with counters stored in 10 MB of shared memory. Next, add a location block for the login page in your server block:

location = /wp-login.php {
    limit_req zone=login burst=3 nodelay;
    limit_req_status 429;
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}

The burst of 3 lets a real user load the page and submit the form without hitting the limit. Requests past the burst get HTTP 429. Check that your fastcgi_pass line matches your PHP version and socket path. If your config already has a location block for PHP files, make sure this exact-match block for wp-login.php comes first.

Test the config, then reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

WordPress login rate limiting has one blind spot: it counts requests per IP, so a bot that spreads attempts across many IPs will not trip it. That is where a Fail2ban WordPress login jail helps. For more on what Nginx rate limiting can do beyond the login page, see our guide on how to rate limit Nginx to stop brute force and scraping bots.

Method 2: Block Repeat Offenders with Fail2ban

Fail2ban watches your Nginx access log and bans an IP at the firewall after too many failed logins. Nginx rate limiting slows an attacker down. Fail2ban removes them for a while, and it catches slow attacks that stay under one request per second.

Check that Fail2ban is installed and running:

sudo systemctl status fail2ban

If it is not installed, install it from your distribution repositories. Then create a filter that matches failed login attempts. Create /etc/fail2ban/filter.d/wordpress.conf with this content:

[Definition]
failregex = ^<HOST> - - [.*] "POST /wp-login.php HTTP/.*" 200
ignoreregex =

This pattern matches POST requests to wp-login.php that returned HTTP 200. WordPress returns 200 for a failed login, because it reloads the login page with an error message. A successful login redirects with a 302, so it does not match. If your log format differs, test the pattern against your real log first:

sudo fail2ban-regex /var/log/nginx/access.log /etc/fail2ban/filter.d/wordpress.conf

Next, add a jail in /etc/fail2ban/jail.local:

[wordpress]
enabled = true
filter = wordpress
logpath = /var/log/nginx/access.log
maxretry = 5
findtime = 600
bantime = 3600
port = http,https

These settings ban an IP for one hour after five failed logins within ten minutes. Restart Fail2ban, then check that the jail is active:

sudo systemctl restart fail2ban
sudo fail2ban-client status wordpress

The output should list the filter, the log path, and zero banned IPs at first. If the jail shows as missing, check /var/log/fail2ban.log. For more on how jails, filters, and actions fit together, read Fail2ban jails explained, and how to protect SSH, WordPress, and mail services.

Method 3: Rate Limit at the Edge with Cloudflare

Cloudflare rate limiting can block login attempts before the traffic reaches your VPS at all. This helps when the attack is spread across many IPs, because Cloudflare sees the traffic from its edge and can apply one rule to the login URL across all of them.

In the Cloudflare dashboard, open your domain, go to Security, then WAF, then Rate limiting rules. Create a rule that matches requests to /wp-login.php, with a limit such as 5 requests per minute per IP, and an action of Block or Challenge for one hour. Field names change as Cloudflare updates its dashboard, so follow the labels on the screen rather than a screenshot from an old tutorial.

Rate limiting rules sit in the paid part of Cloudflare on some plans, so check official pricing before you plan around them. If you run Cloudflare in front of Nginx, make sure Nginx sees the real visitor IP, not a Cloudflare IP, or your Nginx and Fail2ban limits will count Cloudflare addresses instead of attackers. The usual fix is the real IP module with Cloudflare IP ranges.

What Does Not Work on Nginx

A common mistake is copying an Apache .htaccess rule that limits login attempts and pasting it into an Nginx setup. It will not work. Nginx never reads .htaccess files. Apache reads them per directory on every request, while Nginx reads its own config once at startup and ignores .htaccess entirely. If you find a tutorial that limits logins with .htaccess, translate the idea, not the file. The Nginx limit_req block above is the equivalent.

The same warning applies to Apache modules such as mod_evasive. They do not exist on Nginx. Every limit has to live in Nginx config, in Fail2ban, or at the edge. After you add any rule, test it, as the last section shows, instead of assuming the file you edited is the file the server reads.

Harden the Login Page Itself

Rate limits slow an attacker down, but a weak password still falls eventually. Use a long, random password for every admin account, stored in a password manager, and delete the default admin username if it still exists. Give each person their own account instead of sharing one admin login.

Turn on two-factor authentication for admin accounts. WordPress core does not include it, so this is the one place where a small, well-kept plugin is the practical choice. Pick one with recent updates and keep it updated.

Also close the side doors. XML-RPC is a separate login path that bots use to guess passwords in bulk, and it bypasses the wp-login.php limits above unless you block it too. Our guide on how to disable XML-RPC to stop wp-login brute force attacks walks through the Nginx block for it. WordPress brute force protection works best in layers, so keep WordPress, themes, and plugins updated too.

Test Your Limits Before You Trust Them

A limit you never tested is a guess. Test from a second IP or a phone on mobile data, never from the connection you use to manage the site, so you do not lock yourself out:

for i in 1 2 3 4 5 6 7 8; do
  curl -s -o /dev/null -w "%{http_code}n" https://example.com/wp-login.php
done

Replace example.com with your domain. The first few requests should return 200, and the later ones should return 429 once the burst is used up. If every request returns 200, your location block is not matching, so check the config Nginx actually loaded with sudo nginx -T and look for a conflicting location block.

Test Fail2ban the same way. Send five failed logins from a test IP, then run sudo fail2ban-client status wordpress and check that the IP appears in the banned list. Then unban it with sudo fail2ban-client set wordpress unbanip YOUR_TEST_IP. Check the Fail2ban log if the ban does not appear, because a log path or regex mismatch is the usual cause.

Method Where it runs What it stops
Nginx rate limiting Your VPS Fast bursts from one IP
Fail2ban Your VPS Repeat failures, including slow attacks
Cloudflare rate limiting Edge, before your VPS Distributed attacks across many IPs

Start with Nginx rate limiting, add Fail2ban the same day, and add Cloudflare rate limiting if the attacks keep coming from many addresses at once.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.