Cloudflare for WordPress: DNS, Full (strict) SSL and caching setup
· The AYT team · 7 min read

To use Cloudflare with WordPress, add the domain to your Cloudflare account, change the nameservers at your registrar, keep the proxy (the orange cloud) on only for the site's records and set the SSL mode to Full (strict). From day one Cloudflare caches images, CSS and JavaScript, but not HTML pages. Nearly every problem after the switch (redirect loops, error 526, email that stops arriving) comes from three or four settings, which you go through one by one below.
What Cloudflare does for a WordPress site
Cloudflare sits between visitors and your server. With the proxy on, the browser talks to Cloudflare, and Cloudflare fetches the page from your server. You get three things: the domain's DNS runs on a large, fast network, the server's IP no longer shows in DNS, and static files are served from the Cloudflare data centre closest to the visitor.
WordPress, PHP and the database still run on your hosting. If a page is slow to build on the server, Cloudflare only speeds it up if you cache the HTML too, and that needs care (see step 5). For the other causes of a slow site, read the guide on a slow WordPress site.
Step 1: add the domain and change the nameservers
- In your Cloudflare account, add the domain and pick the Free plan, which is enough for most WordPress sites.
- Cloudflare reads the existing DNS records. Compare its list with your current DNS: the A record for the domain,
www, MX, every TXT (SPF, DKIM, DMARC) and any CNAME. A forgotten DKIM TXT record sends the company's email to spam. - At your registrar, replace the old nameservers with the two Cloudflare gives you. For a
.rodomain, you do this in your account at the registrar you bought it from.
Until the zone is active, the site keeps running on the old DNS. If you want to know what happens when nameservers change, see what DNS is.
Step 2: which records go through the proxy
Cloudflare's proxy only understands web traffic (HTTP and HTTPS). Every other service has to reach the server directly, so its record stays "DNS only" (the grey cloud).
| Record | Proxy |
|---|---|
A or AAAA for domain.com, CNAME or A for www |
Proxied (orange) |
webmail |
can be Proxied, it's a web page too |
mail, used by MX, IMAP and SMTP |
DNS only |
ftp or any name used for FTP |
DNS only |
| MX, TXT | no proxy |
If you turn mail orange, phones and Outlook can no longer connect to the mailbox, and other servers can no longer deliver your mail.
Step 3: Full (strict) SSL mode
A connection through Cloudflare has two legs: from the visitor to Cloudflare, and from Cloudflare to your server. The SSL/TLS mode decides what happens on the second one.
| Mode | Cloudflare → server | When to use it |
|---|---|---|
| Flexible | HTTP, unencrypted | never for WordPress |
| Full | HTTPS, certificate not checked | only temporarily, with a self-signed certificate |
| Full (strict) | HTTPS, certificate checked | the right choice when the server has a valid certificate |
You change the mode under SSL/TLS → Overview. There you can let Cloudflare choose ("Automatic SSL/TLS", which tests the server and never drops to a less secure mode) or pick the mode yourself. If the server has a valid Let's Encrypt certificate, choose Full (strict) straight away.
Flexible causes two problems on WordPress. First, if the server redirects HTTP to HTTPS, Cloudflare requests the page over HTTP, the server sends it to HTTPS, Cloudflare requests it over HTTP again, and the browser shows ERR_TOO_MANY_REDIRECTS (the fix is in the guide to the redirect loop). Second, WordPress thinks it runs on HTTP and builds http:// links, which is exactly the mixed content covered in HTTPS for WordPress.
Step 4: the HTTPS redirect and 301 redirects
You can force HTTPS in two ways: "Always Use HTTPS" under SSL/TLS → Edge Certificates, or the redirect on the server. With Full (strict) both can run together without a loop, because Cloudflare reaches the server over HTTPS anyway.
A 301 redirect for a whole domain (say old-domain.com to domain.com) can be done in Cloudflare under Rules → Redirect Rules, without touching the server. The old domain needs a record with the proxy on, or the request never reaches Cloudflare. Page-level redirects are explained in the guide to the WordPress 301 redirect.
Step 5: caching
Out of the box, Cloudflare caches files by extension (images, CSS, JS, fonts, PDF), but not HTML. For WordPress pages you have three options:
- Leave HTML uncached by Cloudflare and rely on your host's page cache. It's the simplest option and breaks nothing.
- Automatic Platform Optimization (APO), Cloudflare's service built for WordPress. It needs the official Cloudflare plugin in WordPress, which purges the cache when you publish. Check on Cloudflare's site whether APO is included in your plan.
- Your own rule under Caching → Cache Rules that caches HTML too. It must bypass
/wp-admin,wp-login.phpand visitors with thewordpress_logged_in_,wp-postpass_andcomment_author_cookies, pluswoocommerce_items_in_cartandwp_woocommerce_session_on WooCommerce. Without those exceptions, a visitor can get a page with someone else's admin bar or cart.
After you change CSS or the theme, purge the cache under Caching → Configuration → Purge Cache, or visitors get the old files.
Cloudflare errors 521, 522, 525 and 526
An error page with the Cloudflare logo tells you where the connection broke.
| Error | What it means | What to check |
|---|---|---|
| 521 | the server refused the connection | the server is down or blocks Cloudflare's IPs |
| 522 | the server didn't answer in time | the IP in the A record, the server firewall |
| 523 | the server can't be reached | a wrong IP in DNS |
| 524 | the server answered, but too late | a PHP script that runs very long (imports, backups) |
| 525 | the SSL handshake failed | the certificate and HTTPS on the server |
| 526 | the server's certificate isn't valid (Full strict) | an expired certificate, or one issued for another name |
A 500 error shown by WordPress comes from the site, even when the domain is behind Cloudflare. What to do about it is in the guide to the WordPress 500 error.
Visitors' real IP addresses
Through the proxy, the server sees Cloudflare's addresses instead of the visitors'. The real address arrives in the CF-Connecting-IP header. If the server doesn't read it, plugins that limit login attempts can block a Cloudflare address instead of the attacker, and your statistics show the same few IPs. Ask your host whether the server restores the real IP.
Frequently asked questions
Do I need the Cloudflare plugin in WordPress?
Only if you use APO or want WordPress to purge Cloudflare's cache when you publish. DNS, the proxy and SSL need no plugin.
Cloudflare on AYT hosting
On AYT WordPress hosting, your DNS can stay with us or move to your own Cloudflare account from the panel: create a Cloudflare API token from the "Edit zone DNS" template plus "Zone: Read", for that zone only, and paste it into the domain's DNS page. After that you edit the records and the proxy (the Proxy switch next to each A, AAAA or CNAME record) from the AYT panel. The "Push this server's records" button writes this server's records into the Cloudflare zone: the domain, www, its subdomains and, if you want, the email records, with mail left as DNS only.

The site's Let's Encrypt certificate is issued and renewed automatically, including www, mail and webmail, so Full (strict) works with no extra setup. The servers read the visitor's real address from CF-Connecting-IP (only for requests that come from Cloudflare's network), so logs, statistics and login limits see the right IP. Sites already have an nginx page cache, HTTP/2 and HTTP/3, so option 1 under caching is a good place to start.
