Under attack? IT Try it free
Blog · DDoS & security

WordPress DDoS attack: how to protect wp-login.php and xmlrpc.php

WordPress is the favourite target of bots and DDoS attacks. Why wp-login.php, xmlrpc.php and search bring the server to its knees, and how to protect them, with and without plugins.

WordPress runs a huge share of the world's websites, which makes it the first target for anyone writing a bot. Many "DDoS attacks" against WordPress aren't even targeted: they are programs roaming the Internet trying the same pages on millions of sites. The problem is that a few hundred requests per second to the right pages are enough to take down a shared hosting account.

Is your site under attack right now? Don't wait until the end of the article: there are five things to do right away and a form that alerts our staff.What to do now

Why WordPress suffers so much

An uncached WordPress page means starting PHP, loading every plugin and running dozens of database queries. An ordinary server handles a few dozen per second. If a bot asks for hundreds, PHP processes run out, requests queue up and the site stops answering everyone.

The targeted pages are almost always the same.

wp-login.php

The login page can't be cached and makes the database and PHP work on every attempt. Bots use it to try passwords in bulk (brute force): even when they don't guess, trying thousands of times a minute is enough to slow everything down.

xmlrpc.php

It's an old interface for publishing from external apps. It has two well-known flaws:

If you don't use the WordPress mobile app, Jetpack or services that explicitly require it, you can switch it off.

Site search

A search (/?s=word) queries the database every time, and every different word is a new page no cache has ready. A bot searching random words is a simple, effective way to overwhelm a site.

admin-ajax.php and wp-cron.php

Many plugins use admin-ajax.php for dynamic features, and wp-cron.php runs on every visit to execute scheduled tasks. Under attack, both multiply the server's workload.

Defences, from the simplest

1. Switch off xmlrpc.php if you don't need it

With Nginx:

location = /xmlrpc.php { deny all; }

With Apache, in the .htaccess file:

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

Plugins can also disable it, but blocking it at the web server is more effective: the request is refused before PHP even starts.

2. Protect the login

3. Cache your pages

A cached page doesn't start PHP or touch the database: the server delivers it like a file. A caching plugin (or your host's cache) cuts the load ten- or a hundredfold for public pages, and often that alone is enough to survive a spike that used to take the site down.

Caching doesn't protect dynamic pages (login, search, cart), though, and that's exactly where attacks aim.

4. Move cron to a real scheduled task

In wp-config.php:

define('DISABLE_WP_CRON', true);

then add a scheduled task on the server that calls wp-cron.php every five minutes. Cron no longer runs on every visit.

5. Put WordPress behind a CDN with bot protection

All the previous measures run on your server: they help, but requests still reach it. A CDN moves the defence in front of the server.

With 1PrimeCDN:

Logged-in WordPress users aren't served from the cache: pages requested with a session cookie always reach the site, so the admin area and the editor work as before.

6. Let WordPress see visitors' real IP

Behind a CDN, WordPress sees every visit coming from the node addresses. Security plugins, statistics and login attempt limits need to read the real IP, which 1PrimeCDN nodes pass in the X-Forwarded-For header (and in X-PrimeCDN-Client-IP). In the panel, under Pull Zone → Origin, you'll find ready-made lines to paste into wp-config.php, with the node list already included.

Summary

Problem Server-side defence CDN defence
Brute force on wp-login.php Attempt limits, 2FA Per-IP limits, scoring and automatic blocking
xmlrpc.php Block it if unused Per-IP limits and scoring on the nodes
Site search Limit searches Per-IP limits, check under attack
Spikes on public pages Caching plugin Caching on the nodes
Attack hitting the server's IP Firewall Server open only to the nodes

If WordPress is already down right now, start from website under DDoS attack: what to do right now or write to us from the emergency page.

Want a site that holds up even under attack?

1PrimeCDN puts your site behind 8 European nodes with caching, HTTPS and Shield against bots and attacks. Fixed monthly price from €9.90.

Let's talk