Need your WordPress website to be lightning-fast and able to handle tons of traffic? Proxy caching is an extremely effective technique to do this.

WordPress is a fantastic CMS but it can be pretty slow as each page is rendered from scratch on each request to your server. One of the many services Cloudflare offer is proxy caching which is one of the most effective ways to handle large amounts of traffic. It works by routing your traffic through Cloudflare’s servers so they can cache a copy of the rendered page. Subsequent requests to the same page are incredibly quick and don’t even need to make a request to your own WordPress site. If that sounds a bit confusing, the below diagram should help:

Create a Free CloudFlare account

To get started, sign up to CloudFlare at https://www.cloudflare.com/. After signing up, you’ll be prompted to add a website by entering your domain name and choosing a plan. Enter the domain for your WordPress site, and choose the free plan.

Update Your CloudFlare DNS

In the next step, we will be switching the domain name servers to CloudFlare. In order to do this without the downtime, you should enter your DNS values into CloudFlare exactly as they are with your current DNS provider. Select the website within CloudFlare and click the DNS icon; you should be able to add your DNS records on this page.

Switch Your Name Servers to CloudFlare

For CloudFlare to work, the name servers for your domain need to be set to Cloudflare provided ones. Visit the CloudFlare dashboard and you will see what you need to set them to for it to work. Add the new name servers to your domain in your domain registrar dashboard. This update can take 24-48 hours to propagate throughout the internet but it’s usually much quicker.

Enable SSL/TLS (HTTPS)

This step isn’t required but is highly recommended as all websites should be using HTTPS these days. CloudFlare has a few modes that this can be set to:

Encryption modeWhat is it?
OffInsecure, your website will use http rather than https
FlexibleTraffic between your users and CloudFlare is encrypted and will use https. Requests from CloudFlare to your WordPress site will not require https.
FullTraffic between your users and CloudFlare is encrypted and will use https. Requests from CloudFlare to your WordPress site use https with self-signed certificates.
Full (Strict)Traffic between your users and CloudFlare is encrypted and will use https. Requests from CloudFlare to your WordPress site use https. Your origin server must use a certificate from a trusted CA (Certificate Authority) or a CloudFlare Origin CA Certificate. This option sounds complex but is actually pretty simple, and the origin certificates can be valid for a very long time (mine is 15 years).

We will be using Full (Strict) as it’s the most secure way of using CloudFlare. Switch this on within CloudFlare by clicking “SSL/TLS” and selecting “Full (Strict)”. If you don’t want to install a certificate on your server choose “Flexible” and skip the next section.

Installing Your Origin Certificate (Required for Full/Strict Encryption Mode)

Within CloudFlare, click “SSL/TLS”, then click on “Origin Server”. Click the button to create a certificate, you should be able to leave the remaining settings as the default to do the following:

  • Let CloudFlare generate your private key and CSR
  • Include the full domain as well as subdomains
  • Set the validity to 15 years

Accept these settings and you should be given a certificate and key in .pem format. Save the files as your-site-cert.pem and your-site.key. CloudFlare have some great documentation for adding this key to your server configuration (NGINX, Apache, IIS etc): https://support.cloudflare.com/hc/en-us/articles/115000479507-Managing-Cloudflare-Origin-CA-certificates#h_0eadeb1e-93cd-4698-937d-fb5165d40b54.

In the next section we’ll assume you’ve followed the CloudFlare guide and the origin certificate is installed correctly.

WordPress Page Rules

You’ll probably notice that we’ve enabled CloudFlare but caching is not working. This is because CloudFlare needs a bit more guidance on what pages to cache. We can do this by defining “Page Rules” within CloudFlare. Navigate to the “Page Rules” section and add the following rules:

RuleBehaviourOrder
your-domain.com/wp-admin/*BypassFirst
your-domain.com/*Cache everythingLast

The first rule bypasses all caching for our admin section of WordPress, this is entirely dynamic so shouldn’t be cached by CloudFlare. The second rule enables caching for everything else.

That’s It!

That’s all there is to it. CloudFlare will now cache all of your content so your site will be lightning-fast and able to handle tons of traffic. You also get out of the box benefits of using CloudFlare such as DoS (Denial of Service) protection for free!

Just remember that when you make any changes to your blog you’ll need to clear the cache (purge) for the affected pages within CloudFlare otherwise your users may not see them.