Year-end offer: 30% off your first 6 months. Order by 31 December.

Stop WordPress login and xmlrpc.php bot attacks on Nginx and Apache

Almost every WordPress site on a public VPS gets hammered daily by automated bots hitting xmlrpc.php and wp-login.php. Even when they fail to log in, thousands of PHP requests chew through RAM and slow down real visitors. Here is how to block them at the web server before PHP even starts.

Short version: block xmlrpc.php in Nginx or Apache unless you specifically rely on Jetpack or the WordPress mobile app, rate-limit wp-login.php at the web server, and add Fail2ban on repeated failed logins.

Why blocking bots in PHP plugins is too late

Security plugins inside WordPress run inside PHP, which means WordPress boots, opens a MySQL connection, and loads options on every bot hit just to say "blocked." Stopping bots inside Nginx or Apache drops the request in microseconds using almost zero CPU or database load.

1. Check if bots are hitting your site right now

Inspect the last 50 hits in your Nginx or Apache access log:

sudo grep -E "xmlrpc\.php|wp-login\.php" /var/log/nginx/access.log | tail -n 30
# Apache: /var/log/apache2/access.log

If you see hundreds of POST requests per hour from different IP addresses, bots are testing stolen passwords and running PHP workers constantly.

2. Block xmlrpc.php in Nginx or Apache

Most modern WordPress sites do not use XML-RPC at all. If you do not connect via the WordPress mobile app or external Jetpack services, block /xmlrpc.php outright.

In Nginx (inside your site's server { } block):

location = /xmlrpc.php {
    deny all;
    access_log off;
    log_not_found off;
    return 403;
}

In Apache (inside your virtual host or .htaccess):

<Files "xmlrpc.php">
    Require all denied
</Files>

Test your configuration before reloading: sudo nginx -t && sudo systemctl reload nginx (or sudo apachectl configtest && sudo systemctl reload apache2).

3. Rate-limit wp-login.php in Nginx

You still need wp-login.php yourself, so instead of blocking it completely, slow down repeated guesses per IP. Add a shared limit zone inside http { } in /etc/nginx/nginx.conf:

limit_req_zone $binary_remote_addr zone=wplogin:10m rate=5r/m;

Then apply that zone to wp-login.php inside your site config:

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

Replace the PHP socket path with the PHP-FPM version running on your server. See our fuller guide to Nginx rate limiting on Ubuntu and Debian for safe defaults.

4. Ban repeat offenders automatically with Fail2ban

Pair web-server limits with Fail2ban so IPs that repeatedly hammer logins get dropped at the firewall for hours instead of tying up Nginx connections. Follow our guides on setting up Fail2ban on Ubuntu and Debian and hardening WordPress on Ubuntu and Debian.

← Back to the security blog