WordPress Security Hardening Guide 2025: Protect Your Site from Threats

Server-level Nginx rules, fail2ban configuration, WAF setup, SSL hardening, and managed WordPress security best practices for UK hosting.

WordPress powers over 43% of all websites, making it the most targeted CMS by attackers. In 2024 alone, over 90 million WordPress attacks were blocked per month by security providers. For UK businesses, a compromised WordPress site means not just downtime but potential UK GDPR fines, customer data exposure, and reputational damage.

This guide covers every layer of WordPress security โ€” from server-level hardening to application-level protections โ€” so you can run a WordPress site that's genuinely secure, not just "good enough."

Layer 1: Server-Level Security

Your WordPress site is only as secure as the server it runs on. Here's how we harden hosting environments at Hostingowy:

1.1 SSH Hardening

Disable password authentication and use SSH keys only. Change the default SSH port and install fail2ban to rate-limit login attempts:

# /etc/ssh/sshd_config
PasswordAuthentication no
PubkeyAuthentication yes
Port 2222
PermitRootLogin prohibit-password

# Then restart SSH and configure fail2ban
sudo systemctl restart sshd
sudo fail2ban-client set sshd maxretry 3
sudo fail2ban-client set sshd bantime 3600

1.2 Nginx Hardening

Default Nginx installations are surprisingly insecure. Here are the minimum hardening rules every WordPress host should apply:

# Disable server tokens (hides Nginx version)
server_tokens off;

# Limit request size to prevent buffer overflow attacks
client_max_body_size 10M;

# Add security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;

# Rate limit wp-login.php
location = /wp-login.php {
    limit_req zone=wplogin burst=5 nodelay;
    # ... standard PHP fastcgi config
}

# Block access to sensitive files
location ~* /(wp-config\.php|wp-admin/includes|wp-includes/.*\.php) {
    deny all;
    return 403;
}

# Block XML-RPC unless explicitly needed (prevents brute-force attacks)
location = /xmlrpc.php {
    deny all;
    return 403;
}

1.3 Fail2Ban for WordPress

Fail2Ban monitors log files and bans IPs showing malicious behaviour. Here's a custom WordPress fail2ban filter:

# /etc/fail2ban/jail.d/wordpress.conf
[wordpress]
enabled  = true
port     = http,https
filter   = wordpress
logpath  = /var/log/nginx/access.log
maxretry = 5
bantime  = 86400
findtime = 600

# /etc/fail2ban/filter.d/wordpress.conf
[Definition]
failregex = ^<HOST> .* "POST .*wp-login\.php
            ^<HOST> .* "POST .*xmlrpc\.php
            ^<HOST> .* .* 404 .*wp-content/plugins/.*
ignoreregex =

Layer 2: WordPress Application Security

2.1 Update Everything, Always

Over 60% of WordPress hacks come from outdated core, plugins, or themes. Enable automatic updates for core and audit plugins regularly:

2.2 Hardened wp-config.php

// Disable file editing from the admin panel
define('DISALLOW_FILE_EDIT', true);

// Disable plugin and theme installation from admin
define('DISALLOW_FILE_MODS', true);

// Set secure salts and keys (use https://api.wordpress.org/secret-key/1.1/salt/)
define('AUTH_KEY',         'your-random-key-here');
define('SECURE_AUTH_KEY',  'your-random-key-here');
define('LOGGED_IN_KEY',    'your-random-key-here');
define('NONCE_KEY',        'your-random-key-here');
define('AUTH_SALT',        'your-random-key-here');
define('SECURE_AUTH_SALT', 'your-random-key-here');
define('LOGGED_IN_SALT',   'your-random-key-here');
define('NONCE_SALT',       'your-random-key-here');

// Force SSL for admin and login
define('FORCE_SSL_ADMIN', true);

// Limit post revisions to prevent database bloat
define('WP_POST_REVISIONS', 10);

// Set automatic garbage collection for transients
define('WP_AUTO_UPDATE_CORE', true);

2.3 User Management Best Practices

Layer 3: Web Application Firewall (WAF)

A WAF filters out malicious traffic before it reaches WordPress. There are two approaches:

Type Pros Cons Recommendation
Cloud WAF (Cloudflare, Sucuri) DDoS protection, CDN, no server load DNS change required, monthly cost Best for most sites
Server-level WAF (ModSecurity) No external dependency, full control Performance overhead, complex config Good for high-traffic sites
Plugin WAF (Wordfence, Sucuri) Easy setup, WordPress integration Consumes PHP resources, limited at network level Good starting point
Our recommendation: Use a cloud WAF (Cloudflare free tier is excellent) combined with a server-level Nginx rule set. This gives you defence-in-depth without slowing down your WordPress admin.

Layer 4: SSL/TLS Configuration

HTTPS is non-negotiable in 2025. But not all SSL configurations are equal. Here's how to configure TLS properly:

# /etc/nginx/conf.d/ssl.conf
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;

# HSTS (uncomment after confirming HTTPS works)
# add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always;

Layer 5: Backup & Recovery Plan

Even the most secure WordPress site can be compromised. A proper backup strategy limits damage to hours instead of weeks:

The 3-2-1 Backup Rule Applied to WordPress

At Hostingowy, every managed WordPress plan includes:

WordPress Security Checklist for UK Businesses

How Hostingowy Keeps WordPress Sites Secure

Every managed WordPress hosting plan at Hostingowy includes server-level security as standard:

Get Secure Managed WordPress Hosting

Enterprise-grade WordPress security with European data centres (Poland), daily backups, and real UK engineering support. Starting from ยฃ15/mo.

See Plans โ†’

Related reading: WordPress Performance Tuning: From 2s to 200ms โ€ข UK GDPR Hosting Compliance Guide โ€ข Ultimate Guide to UK VPS Hosting

๐Ÿš€

The Hostingowy Engineering Digest

Get monthly deep-dives on UK VPS hosting, infrastructure benchmarks, DevOps tooling, and cloud cost optimisation. Built by engineers, for engineers.

2 issues sent ยท 7 subscribers ยท No spam, ever

No spam. Unsubscribe anytime. Read our Privacy Policy.