How to Set Up Cloudflare WAF for WordPress
Step-by-step guide to configuring Cloudflare Web Application Firewall to protect your WordPress site from attacks.
Cloudflare's WAF provides excellent protection for WordPress sites against common attacks like SQL injection, cross-site scripting (XSS), and brute force login attempts.
This guide walks you through the complete setup process, from adding your domain to Cloudflare to configuring WordPress-specific security rules.
Prerequisites
- A WordPress website hosted on any web server
- Access to your domain registrar to change nameservers
- A Cloudflare account (free tier works) Learn more
Step-by-Step Guide
Add Your Domain to Cloudflare
Log into your Cloudflare dashboard and click "Add a Site". Enter your domain name (without www) and click "Add Site".
Cloudflare will scan your existing DNS records. Review them to ensure all your subdomains and mail records are included.
Update Your Nameservers
Cloudflare will provide you with two nameservers. Log into your domain registrar and replace your current nameservers with the Cloudflare ones.
DNS propagation can take up to 24 hours, but usually completes within a few hours.
Configure SSL/TLS Encryption
Before enabling the WAF, set a secure encryption mode so traffic is protected end to end:
- Go to SSL/TLS > Overview and set the encryption mode to Full (Strict).
- Full (Strict) requires a valid TLS certificate on your origin server. If your host does not already provide one, install a free certificate: use Let's Encrypt, or generate a Cloudflare Origin CA certificate under SSL/TLS > Origin Server > Create Certificate and install it on your origin.
- Use Full (without Strict) only as a short interim step while you provision a trusted certificate.
Enable Cloudflare WAF
Once your domain is active on Cloudflare, deploy the managed rulesets:
- Go to Security > Settings and filter by "Web application exploits" (in the legacy dashboard: Security > WAF > Managed rules).
- Turn on the Cloudflare Managed Ruleset.
- Optionally turn on the Cloudflare OWASP Core Ruleset. It is prone to false positives, so tune it before you let it block traffic.
To tune the OWASP ruleset, select the Cloudflare OWASP Core Ruleset from the managed rules list to open its configuration, then set the OWASP Paranoia Level (PL1-PL4), the OWASP Anomaly Score Threshold (Low, Medium, or High), and the OWASP Action (Log, Block, or a challenge). Start at PL1 with the action set to Log, then raise the sensitivity gradually while watching for false positives.
Configure WordPress-Specific Rules
Create custom rules to protect WordPress-specific endpoints:
- Go to the Security rules page and select "Create rule", then "Custom rules" (in the legacy dashboard: Security > WAF > Custom rules).
- Create a rule to protect wp-login.php from brute force attacks.
- Consider blocking access to xmlrpc.php if not needed.
- Select "Deploy" to activate the rule.
# Block xmlrpc.php (if you don't use it)
Rule Name: Block XML-RPC
Expression: (http.request.uri.path eq "/xmlrpc.php")
Action: Block
Install Cloudflare Plugin (Optional)
Install the official Cloudflare WordPress plugin for better integration:
- Go to Plugins > Add New in WordPress
- Search for "Cloudflare"
- Install and activate the official Cloudflare plugin
- Connect it with your Cloudflare API token
Test Your Configuration
After setup, test that your site works correctly:
- Visit your site and verify it loads properly
- Test logging into WordPress admin
- Check that comments and forms still work
- Monitor the Cloudflare dashboard for any blocked requests
Conclusion & Next Steps
Your WordPress site is now protected by Cloudflare's WAF. The managed rulesets will automatically block most common attacks, and your custom rules provide additional WordPress-specific protection.
Next steps:
- Review blocked threats regularly on the Security > Events page (Security > Analytics in the newest dashboard)
- Consider upgrading to Cloudflare Pro for additional WAF features
- Enable Bot Fight Mode for additional bot protection
Troubleshooting
Site shows SSL errors
In Cloudflare's SSL/TLS settings, set the encryption mode to Full (Strict). This requires a valid TLS certificate on your origin server. If your host does not provide one, install a free certificate: use Let's Encrypt, or generate a Cloudflare Origin CA certificate under SSL/TLS > Origin Server > Create Certificate. Full (without Strict) is acceptable only as an interim step while you provision a trusted certificate. Do not fall back to Flexible mode, which leaves the origin connection unencrypted and is unsafe for sites with a login.
Forms or login not working
Check Security > Events for blocked requests. You may need to create an exception (skip) rule for legitimate traffic.
Site is slow after setup
Enable Cloudflare's caching features and consider enabling Rocket Loader for JavaScript optimization.
Frequently Asked Questions
Is Cloudflare WAF free?
Yes, the basic Cloudflare WAF is included in the free plan. It includes managed rulesets that protect against common attacks. More advanced features like additional custom rules and detailed analytics are available on paid plans.
Will Cloudflare slow down my WordPress site?
No, Cloudflare typically makes WordPress sites faster by caching static content and serving it from edge locations closer to your visitors. The WAF inspection adds minimal latency (usually less than 1ms).