Tutorial

WordPress Cloudflare Setup: The Complete 2026 Guide to Speed and Security

April 17, 2026

Back to Blog

WordPress powers over 43% of the entire web. Cloudflare sits in front of millions of those sites, providing a CDN, DDoS protection, and a free SSL certificate. But here is the problem: the default Cloudflare settings are not optimized for WordPress, and one wrong toggle can take your entire site down with a white screen of death or an infinite redirect loop.

This guide walks you through every critical Cloudflare setting for WordPress — from initial DNS setup to advanced caching rules — so you get maximum speed and security without the headaches. Whether you are running a personal blog or a high-traffic WooCommerce store, these steps apply to every WordPress + Cloudflare setup.

What You Will Learn: How to properly configure Cloudflare for WordPress, avoid the dreaded redirect loop, set up optimal caching rules, harden security with WAF, and squeeze every millisecond out of your page load times.

Prerequisites Checklist

Before you begin, make sure you have the following ready:

  • A working WordPress installation (self-hosted, not WordPress.com)
  • A registered domain name pointing to your server
  • A Cloudflare account (the free plan works for everything in this guide)
  • SSH or SFTP access to your server (for wp-config.php edits)
  • Access to your domain registrar to change nameservers
  • Your origin server IP address (the real IP, not Cloudflare's)

Step 1: Add Your Domain to Cloudflare

The first step is onboarding your domain into Cloudflare's network. This is straightforward, but there is one critical mistake people make that can cause downtime.

1
Create a Cloudflare Account

Go to dash.cloudflare.com and sign up with your email address. Verify your email before proceeding.

2
Add Your Site

Click "Add a Site" and enter your root domain (e.g., example.com, not www.example.com). Select the Free plan — you can upgrade later if needed.

3
Review DNS Records

Cloudflare will scan your existing DNS records. Carefully verify that every record was imported correctly. Pay special attention to MX records (email), CNAME records, and any TXT records (SPF, DKIM, DMARC). Missing mail records will break your email delivery.

4
Change Your Nameservers

Cloudflare will give you two nameservers (e.g., ada.ns.cloudflare.com and bob.ns.cloudflare.com). Log in to your domain registrar and replace the existing nameservers with these. Propagation takes anywhere from 5 minutes to 48 hours, but usually completes within 1-2 hours.

Important: Do NOT change your nameservers before verifying that all DNS records were imported correctly. If Cloudflare missed your MX records, your email will stop working the moment the nameserver change propagates. Double-check everything first.

Step 2: SSL Configuration — The Most Critical Step

This is where most WordPress + Cloudflare setups go wrong. Cloudflare offers four SSL modes, and choosing the wrong one will either break your site or create a security vulnerability.

Browser
HTTPS
Cloudflare
HTTPS
WordPress
SSL Mode Browser → CF CF → Origin Recommendation
Off HTTP HTTP Never Use
Flexible HTTPS HTTP Causes Redirect Loops
Full HTTPS HTTPS (any cert) Acceptable
Full (Strict) HTTPS HTTPS (valid cert) Always Use This
Never Use Flexible SSL with WordPress. When you set Cloudflare to Flexible, visitors connect to Cloudflare over HTTPS, but Cloudflare connects to your server over plain HTTP. WordPress sees an HTTP request and tries to redirect to HTTPS. Cloudflare converts that back to HTTP. The result: an infinite redirect loop (ERR_TOO_MANY_REDIRECTS). This is the number one cause of WordPress + Cloudflare issues.

To configure SSL correctly:

  1. In Cloudflare dashboard, go to SSL/TLS → Overview
  2. Set encryption mode to Full (Strict)
  3. Make sure your origin server has a valid SSL certificate (Let's Encrypt is free and works perfectly)
  4. Enable Always Use HTTPS under SSL/TLS → Edge Certificates
  5. Enable Automatic HTTPS Rewrites to fix mixed content
Cloudflare Origin Certificate: If you do not have an SSL cert on your origin server, you can generate a free Cloudflare Origin Certificate from the dashboard (SSL/TLS → Origin Server). This certificate is trusted only by Cloudflare, so it works perfectly for the CF → Origin connection but will not work if visitors bypass Cloudflare.

Step 3: WordPress Configuration

With Cloudflare proxying your traffic, WordPress needs to be told that it is behind a reverse proxy. Without this configuration, WordPress will think all requests come from Cloudflare's IP addresses, and it will not detect HTTPS correctly.

Add the following to your wp-config.php file, before the line that says /* That's all, stop editing! */:

// Trust Cloudflare proxy headers
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
    $_SERVER['HTTPS'] = 'on';
}

// Restore real visitor IP from Cloudflare
if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
    $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CF_CONNECTING_IP'];
}

// Force SSL for admin
define('FORCE_SSL_ADMIN', true);
Check Your Site URLs: In WordPress admin, go to Settings → General and make sure both "WordPress Address (URL)" and "Site Address (URL)" use https://. If they are set to http://, update them. If you are locked out due to redirect issues, you can set these in wp-config.php:

define('WP_HOME', 'https://example.com');
define('WP_SITEURL', 'https://example.com');

Step 4: Cache Configuration

Cloudflare's default caching is conservative. It caches static assets (images, CSS, JS) but does not cache HTML pages. For a WordPress site, you want to cache everything except dynamic pages like the admin area and login page.

What to Cache vs. What to Skip

URL Pattern Cache? Reason
/wp-content/uploads/* Yes — Cache Everything Static images, never change
/wp-content/themes/* Yes — Cache Everything CSS, JS, images from theme
/wp-content/plugins/* Yes — Cache Everything Plugin static assets
Blog posts and pages Yes, with Edge TTL HTML pages, set 2h TTL
/wp-admin/* Never Admin panel, dynamic content
/wp-login.php Never Login page with CSRF tokens
/wp-json/* Never REST API, dynamic responses
/wp-cron.php Never WordPress scheduler
Logged-in users Never User-specific content

Setting Up Cache Rules

In your Cloudflare dashboard, go to Caching → Cache Rules and create these rules in order:

1
Bypass Cache for Admin & Login

Match: URI Path starts with "/wp-admin" OR URI Path equals "/wp-login.php" OR URI Path starts with "/wp-json"
Action: Bypass Cache

2
Bypass Cache for Logged-in Users

Match: Cookie contains "wordpress_logged_in" OR Cookie contains "wp-settings"
Action: Bypass Cache

3
Cache Static Assets Aggressively

Match: URI Path starts with "/wp-content/uploads"
Action: Cache Everything, Edge TTL: 1 month, Browser TTL: 1 month

Pro Tip: After setting up cache rules, purge your entire Cloudflare cache once (Caching → Configuration → Purge Everything). This ensures the new rules take effect immediately without stale cached pages interfering.

Step 5: Security Settings

Cloudflare's WAF (Web Application Firewall) can block common WordPress attacks before they reach your server. Here are the essential security rules to configure.

Block XML-RPC

The xmlrpc.php file is WordPress's legacy API. It is rarely needed anymore (the REST API replaced it), and it is one of the most exploited attack vectors for brute force and DDoS amplification attacks.

1
Create a WAF Custom Rule

Go to Security → WAF → Custom Rules. Create a rule:
Match: URI Path equals "/xmlrpc.php"
Action: Block

Protect wp-login.php with Rate Limiting

2
Rate Limit Login Attempts

Create a rate limiting rule:
Match: URI Path equals "/wp-login.php" AND Request Method equals "POST"
Rate: 5 requests per 10 seconds
Action: Challenge (CAPTCHA) for 1 hour

Block Sensitive Paths

3
Block Access to Sensitive Files

Create a WAF rule to block direct access to:
URI Path contains "wp-config.php" OR URI Path contains ".env" OR URI Path starts with "/.git"
Action: Block

Country Blocking: If your site serves a specific geographic audience, you can block traffic from countries where you have no visitors. Go to Security → WAF → Custom Rules, match on "Country" and block or challenge. This dramatically reduces bot traffic and brute force attempts.

Step 6: Performance Optimization

Beyond caching, Cloudflare offers several performance features that work well with WordPress — but some of them can cause issues.

Auto Minify Enable

Go to Speed → Optimization → Content Optimization. Enable minification for HTML, CSS, and JavaScript. This reduces file sizes by removing whitespace and comments. Safe for virtually all WordPress sites.

Brotli Compression Enable

Found under Speed → Optimization. Brotli compresses better than gzip (15-20% smaller files). Enable it — there is no downside. All modern browsers support it.

Early Hints (103) Enable

Under Speed → Optimization. Early Hints tells the browser to start loading critical CSS and JS before your server even finishes generating the page. Free performance boost with no risk.

Rocket Loader Use with Caution

Rocket Loader defers all JavaScript execution. While this can improve initial paint time, it frequently breaks inline scripts, analytics trackers, and plugin-dependent JavaScript. Test thoroughly before leaving it enabled.

HTTP/2 and HTTP/3 Enable

These are enabled by default on Cloudflare. HTTP/2 multiplexes requests, and HTTP/3 (QUIC) reduces latency. No configuration needed — just verify they are on in the Network section.

Image Optimization Pro Plan

Cloudflare Polish (lossy/lossless compression) and WebP conversion are Pro plan features. If you are on the free plan, use a WordPress plugin like ShortPixel or Imagify instead.

Common Issues and Fixes

Even with perfect configuration, issues can arise. Here are the most common WordPress + Cloudflare problems and their solutions.

Infinite Redirect Loop (ERR_TOO_MANY_REDIRECTS)

Cause: SSL mode set to "Flexible" while WordPress forces HTTPS.
Fix: Change SSL mode to Full (Strict). Install a valid SSL certificate on your origin server. Clear browser cookies and Cloudflare cache.

White Screen of Death

Cause: Rocket Loader breaking critical JavaScript.
Fix: Disable Rocket Loader in Speed → Optimization. If the issue persists, disable Auto Minify for JavaScript. Check your browser console for errors.

REST API Returns 403

Cause: Cloudflare WAF or a security rule blocking /wp-json/ requests.
Fix: Check Security → Events for blocked requests. Create a WAF exception rule to allow /wp-json/ paths. This is essential for Gutenberg editor and many plugins.

Cannot Login to wp-admin (403 Forbidden)

Cause: WAF rule or Bot Fight Mode blocking your IP.
Fix: Whitelist your IP in Security → WAF → Tools → IP Access Rules. If using Bot Fight Mode, create a Skip rule for /wp-admin/* and /wp-login.php paths.

Images Not Loading (Mixed Content)

Cause: Image URLs still using http:// in the database.
Fix: Enable "Automatic HTTPS Rewrites" in SSL/TLS settings. For a permanent fix, run a search-replace in the database to update all http:// URLs to https://. WP-CLI: wp search-replace 'http://example.com' 'https://example.com'

Comments Show Cloudflare IPs

Cause: WordPress logging Cloudflare proxy IPs instead of real visitor IPs.
Fix: Add the HTTP_CF_CONNECTING_IP header restoration code from Step 3 to your wp-config.php. Alternatively, install the official Cloudflare plugin.

Panelica Integration: WordPress + Cloudflare Made Easy

All of the above — automated in one click.

If you are managing WordPress sites on a Panelica-powered server, the entire Cloudflare integration is built right into the panel. Here is what Panelica handles for you:

One-Click WordPress Install

Panelica's WordPress toolkit installs WordPress with optimized PHP-FPM pools, Redis object caching, and correct file permissions — all in under 30 seconds. No manual configuration needed.

Automatic SSL Provisioning

When you add a domain, Panelica automatically provisions a Let's Encrypt SSL certificate and configures Nginx for Full (Strict) compatibility. No redirect loops, ever.

Cloudflare Zone Sync

Connect your Cloudflare API key, and Panelica will automatically sync DNS records when you add domains, create subdomains, or change server IPs. One-click A record and MX record management.

Pre-Configured Security

Panelica's nftables firewall comes pre-configured with Cloudflare IP ranges whitelisted. ModSecurity with OWASP CRS rules protect your WordPress sites at the server level, adding a second layer of security behind Cloudflare's WAF.

Instead of spending an hour configuring Cloudflare settings manually, Panelica gives you a production-ready WordPress + Cloudflare stack in minutes. The panel manages 20+ services including Nginx, PHP-FPM, Redis, and automatic SSL — everything your WordPress site needs to be fast, secure, and reliable.

Learn More: Visit panelica.com to explore how Panelica simplifies server management for WordPress hosting, from one-click installs to automated backups and real-time monitoring.
Share: