How to Connect WordPress to Cloudflare
On this page19 items
Through Chapter 7, we’ve gone over Cloudflare’s main services one by one. Chapter 8, starting here, is the hands-on part. We’ll put what you’ve learned into practice by actually doing it.
The first topic is WordPress. Moving a WordPress site that’s already running on shared hosting or a VPS behind Cloudflare is the most common reason people start using Cloudflare, and the results are clear: pages load faster, attacks drop, and you’re freed from renewing certificates.
However, if you get the order wrong, your site may stop loading or your email may stop arriving. This page walks through the whole process from start to finish, including the spots where people tend to trip up.
What you’ll learn on this page#
- The overall flow of connecting a WordPress site to Cloudflare
- What you must check before changing nameservers
- How to choose an SSL/TLS mode (and why you must not choose Flexible)
- What to cache in WordPress, and what you must not cache
- The minimum settings to configure after connecting
Before you start#
These steps assume the following.
- WordPress is running on your own domain (shared hosting, VPS, or cloud — any is fine)
- You can change the domain’s nameservers yourself (you can log in to your registrar’s dashboard)
- The site loads over
https://(you can proceed even if it isn’t on HTTPS yet, but there will be a few extra steps later)
There are also three things you must record before you begin.
- The full set of current DNS records: From your registrar’s or hosting company’s dashboard, save all A, AAAA, CNAME, MX, and TXT records as notes or screenshots
- Your server’s IP address: The IP address of the server running WordPress
- Your current nameservers: In case you want to switch back
The first one is especially important. Most of the trouble with this task comes from records that were missed when copying them over.

Step 1: Add your domain to Cloudflare#
Create a Cloudflare account and add your domain from the dashboard.
Enter the apex domain (example.com), not a subdomain like www.example.com. You’ll handle www as a record later.
Next, choose a plan. For a personal site, the Free plan is plenty. The differences between plans are explained in An Introduction to Cloudflare’s Plans. You can change it later, so if in doubt, start with Free.
Step 2: Check your DNS records#
When you add a domain, Cloudflare automatically scans your current DNS records and shows a list.
Don’t assume “it was scanned, so it’s fine.” This scan isn’t exhaustive, and the official documentation also asks you to check manually. Compare it line by line with the list of records you saved.
These three are especially easy to miss.
- The
wwwrecord: Without it,www.example.comwill stop working - MX records: These are where your mail is delivered. If they’re missing, email will stop arriving
- TXT records: These are used for SPF, DKIM, and DMARC (email authentication) and for ownership verification by various services. If they’re missing, your email may be treated as spam, or integrations with external services may break
Setting the proxy status (orange cloud)#
Each record has a setting for whether it goes through the proxy.
| Record | Proxy status | Reason |
|---|---|---|
example.com (A) | Proxied (orange cloud) | The site itself. This is what you want to protect |
www (A or CNAME) | Proxied (orange cloud) | Same as above |
| MX records | Can’t be proxied | They can’t be proxied in the first place |
A records such as mail and ftp | DNS only (gray cloud) | Otherwise sending/receiving mail and FTP stop working |
This ties directly into what you learned up through Chapter 5. The moment you switch a record to the orange cloud, access to that hostname goes through Cloudflare and your server’s IP address is hidden. Conversely, gray-cloud records leave the IP address publicly visible as is.
If mail.example.com has to be gray-clouded but that record points to the same IP address as the site itself, your server’s IP is exposed through it. Understand this as an unavoidable reality (the reliable countermeasure is to move mail to a separate host).
Step 3: Change your nameservers#
In the dashboard of the registrar where you got the domain, set the two nameservers Cloudflare assigned you (in the form xxx.ns.cloudflare.com).
Always disable DNSSEC before the change#
If DNSSEC (a feature that prevents DNS tampering) is enabled at your current DNS provider, disable it first. If you switch nameservers with it still enabled, signature validation fails and the entire domain stops resolving. Not “the site is blank,” but “no such domain exists”: the most severe kind of outage.
The safe approach is to disable it, wait a little for the change to propagate through DNS, and then change the nameservers.
Wait for it to take effect#
It takes time for a nameserver change to propagate around the world. Sometimes it’s done in minutes; sometimes it takes around 24 hours. Once the status in the Cloudflare dashboard shows “Active,” you’re done.
The site keeps loading during this wait. People whose resolvers still see the old nameservers go straight to your server as before, and those who see the new nameservers go through Cloudflare. That’s all.
Step 4: Configure the SSL/TLS mode correctly#
This is the single most important setting, and you must check it right after connecting.
As explained on the SSL/TLS page, Cloudflare has several encryption modes. Here’s what matters for WordPress.
- Flexible: HTTPS from the visitor to Cloudflare, but HTTP (unencrypted) from Cloudflare to your server. When WordPress redirects with “please use HTTPS,” Cloudflare sends the request to the server over HTTP again, creating an infinite redirect loop. This is the classic cause of the “too many redirects” error
- Full: HTTPS all the way to the server, but the certificate’s contents aren’t validated
- Full (strict): HTTPS all the way to the server, and it also validates that the server’s certificate is valid (not expired, issued by a trusted certificate authority, and matching the hostname)
Choose Full (strict). The official documentation also explicitly says to “choose Full (strict) whenever possible.”
If your server doesn’t have a valid certificate, install an Origin CA certificate (valid for up to 15 years), issued free by Cloudflare, on the server, and you can use Full (strict). This certificate is only valid for access through Cloudflare, so viewing the server directly in a browser shows a warning, but that’s fine.
Settings to enable alongside it#
- Always Use HTTPS: Automatically redirects HTTP requests to HTTPS. Because it’s handled before WordPress’s own redirect, it also reduces load on your server
- WordPress settings: Under Settings → General in the admin dashboard, check that the WordPress Address and Site Address start with
https://
Step 5: Configure caching#
At this point the connection is complete, but right now Cloudflare only caches static files such as images, CSS, and JavaScript. HTML (the article pages themselves) is fetched from the server every time.
To make WordPress truly fast, you need to cache the HTML too. But this requires care.

Places you must not cache#
- Everything under
/wp-admin/: The admin dashboard. If a cached copy were served to someone else, it would be a disaster /wp-login.php: The login page- Browsing while logged in: WordPress issues logged-in users a cookie starting with
wordpress_logged_in_. Requests with this cookie must not be served from cache - Carts and checkout: If you run e-commerce such as WooCommerce, always exclude
/cart/,/checkout/, and/my-account/ - Contact form submission results: POST requests aren’t cached in the first place
Method 1: Set it up yourself with Cache Rules#
Cache Rules let you define caching behavior based on conditions. The rule limits are Free 10, Pro 25, Business 50, and Enterprise 300.
At a minimum, these two rules get you a working setup.
- Exclusion rule (place it on top so it’s evaluated first): URL path starts with
/wp-admin/, or is/wp-login.php, or the cookie containswordpress_logged_in_→ bypass cache - Caching rule: Everything else → eligible for cache (set the Edge TTL to somewhere between a few hours and a day)
The weakness of this method is that the cache isn’t cleared automatically when you update a post. Either purge the cache from the dashboard each time you update, or combine it with the plugin described below.
Method 2: Use APO (Automatic Platform Optimization)#
APO is a feature that takes care of all of this for WordPress in one go. It uses Workers to cache HTML at the edge, and automatically clears the cache when you update a post. It automatically bypasses the cache for logged-in users.
To use it, install the official WordPress plugin “Cloudflare” and link it to your site with an API token. It costs $5 per month on the Free plan and is included at no extra cost on Pro and above.
Here’s a rough guide for choosing.
| Cache Rules | APO | |
|---|---|---|
| Cost | Free | $5/month on the Free plan / free on Pro and above |
| Setup effort | Build the rules yourself | Just install and enable the plugin |
| Clearing cache on updates | Manual, or combined with a plugin | Automatic |
| Fine-grained control | Very flexible | Fixed behavior |
If WordPress is all you run, trying APO first is the quickest choice. If you want fine-grained control, or if non-WordPress pages live on the same domain, building it yourself with Cache Rules gives you a clearer picture.
Step 6: Minimum security settings#
Just by connecting, DDoS Protection is automatically active on every plan. On top of that, adding the following is very effective for WordPress.
- Apply Rate Limiting to
/wp-login.php: Setting a limit like “up to 5 times per minute” with Rate Limiting all but stops brute-force password attacks. You can create one rule even on the Free plan - Restrict
/wp-admin/by country or IP: With a WAF custom rule, you can block access to the admin dashboard from countries other than the ones you use - Enable Bot Fight Mode: A basic bot protection feature. It’s free
- Block
/xmlrpc.php: If you don’t use it, it’s fine to block it with a WAF custom rule. It’s a well-known entry point for attacks
If you want even stronger protection, you can put Cloudflare Access in front of the admin dashboard and require authentication with something like a Google account. That procedure is covered two pages from now.
Points beginners should watch out for#
- Migrate during low-traffic hours: Rolling back a nameserver switch takes time. Do the work late at night or on a weekend
- Check MX records first: You’ll notice right away if the site doesn’t load, but you might not notice email isn’t arriving for days. After switching, send a test email to yourself to confirm
- After enabling caching, always log out to check: If you stay logged in, you can’t tell whether the cache is working or whether you’re bypassing it because you’re logged in. Check in a private window
- When “I updated it but it’s not showing,” suspect the cache: There are three layers: Cloudflare, your WordPress caching plugin, and the browser. Purge Cloudflare’s cache first, and if that doesn’t fix it, look at the plugin
- Use Development Mode while developing: Enabling Development Mode in the dashboard bypasses the cache completely for 3 hours. It’s handy when working on themes or CSS
- Watch out for double caching with plugins: When both a WordPress caching plugin and Cloudflare’s cache are active, it becomes hard to isolate problems. It’s safest to rely on one or the other
Related services#
- What Is Cloudflare’s Proxy?: What the orange and gray clouds mean
- What Is SSL/TLS?: The basics for understanding Full (strict)
- What Is a CDN?: The mechanism behind cache settings
- What Is Rate Limiting?: Protection against brute-forcing the login page
- What Is a WAF?: Restricting access to the admin dashboard
- What Is Cloudflare Access?: Putting authentication in front of the admin dashboard
Summary#
- Before starting, always record the full set of current DNS records, the server IP, and the current nameservers
- Cloudflare’s automatic scan isn’t exhaustive. Compare
www, MX, and TXT line by line - Orange-cloud the site itself; gray-cloud the mail and FTP hosts
- Always disable DNSSEC before changing nameservers
- Set the SSL/TLS mode to Full (strict). Flexible causes redirect loops
- Cache HTML either by building Cache Rules yourself or by leaving it to APO ($5/month on the Free plan, free on Pro and above)
- Always exclude
/wp-admin/,/wp-login.php, and requests with the logged-in cookie from caching - After switching, always check the site while logged out and confirm that email arrives
Connecting WordPress is a topic where DNS, the proxy, SSL/TLS, caching, and WAF, everything covered in this guide, show up at once. Put the other way around, if you’ve read this far, you should be able to do the work understanding “why” behind every setting.
The next page moves on to exposing a service to the outside without exposing the server, a hands-on exercise with Cloudflare Tunnel.