Cloudflare is a website-security company, providing content delivery network (CDN) services, DDoS mitigation, Internet security and more.
Cloudflare's services sit between a website's visitor and the Cloudflare user's hosting provider (such as Templ), acting as a reverse proxy for websites. Utilizing Cloudflare is an easy way to speed up your WordPress site and increase security.
How to install Cloudflare
This tutorial assumes you already have a Cloudflare account. If you don’t, you can visit the Cloudflare website and sign up for a free account.
Step 1 - Add your site in Cloudflare
Log in to the Cloudflare dashboard and click on “+ Add Site.” Input your WordPress site’s domain (without www or http/https) and click on Add site.
The next step is to choose your plan. Starting with the free plan is fine for most websites.
Click Confirm Plan and then wait for Cloudflare to scan the domains DNS settings and add them automatically.
Step 2 - Verify the DNS Settings
Cloudflare gives you two options. You can use their CDN and protection (which accelerates and protects your sites) or you can simply use their DNS. Most customers will want the former, as this is where you will benefit from everything Cloudflare has to offer. To ensure that your domains are enabled, make sure the cloud is lit up as orange. If you have additional records, such as email (MX records), these should be off Cloudflare (grey).
Confirm your settings and click Continue. You can always modify your records later on.
Step 3 - Change to Cloudflare's nameservers
The next step is to change the nameservers of your domain to point to Cloudflare (you need to use the nameservers they provide).
Cloudflare is a full proxy service which means that you point your domain to Cloudflare, and Cloudflare will then point your domain (website) to Templ using an A-Record (more on that later). There is no downtime when you update your nameservers.
Here's an example of what Cloudflare's nameservers will look like, please note that your nameservers will be different.
Here are links to popular domain registrars and their how-to guides for updating nameservers, be sure to use "Custom DNS".
Allow up to 24 hours for the nameserver change to complete. As soon as the nameservers are updated, you will receive an email from Cloudflare with confirmation.
Step 4 - Point your site to Templ
If your site wasn't already pointing to Templ, now is the time to do so.
The next step is to update the A Record within the Cloudflare dashboard to point to your Templ IP address which be found on the websites overview page in the Templ Panel.
Also make sure you have a CNAME for www that points to your domain name, like in my example above.
That's it. Your site now has Cloudflare installed.
Fixing the Error "ERR_TOO_MANY_REDIRECTS"
This is the most common issue you might come across when you install Cloudflare. Fortunately there is an easy fix for this error. This is because SSL is already installed on the server already and then having the encryption mode set to Flexible in Cloudflare.
In the Cloudflare dashboard, navigate to SSL/TLS and change the Encryption mode to Full to solve this issue.
How to clear the Cloudflare Cache
There are two ways to clear the Cloudflare cache. The first option is to clear the cache in the Cloudflare dashboard. You can choose to purge (clear) the whole cache or do a custom purge.
The second way to clear the Cloudflare cache is to install the Cloudflare plugin for WordPress.
Optional: Install the Cloudflare WordPress plugin
To install the Cloudflare WordPress plugin you can navigate to WP Admin - Plugins - Add New and search for Cloudflare.
Some benefits of installing the Cloudflare plugin includes:
- One-click WordPress-optimized settings
- Automatic cache purge
- Change Cloudflare settings from within the plugin itself without needing to navigate to the cloudflare.com dashboard.
- View analytics such as total visitors, bandwidth saved, and threats blocked
- Support for HTTP2/Server Push
Once you have installed and activated the plugin you will need to input your Cloudflare email address and API key in the settings. You can grab your API key here. Copy the one that says “Global API Key.” Then click on “Save API Credentials.”
You can access the Cloudflare plugin in WP Admin by navigating to Settings - Cloudflare. From here you can purge the Cloudflare cache, check analytics and more.