Sail Knowledgebase

How to Use the Cloudflare Free CDN on your WordPress site with Sail CLI on DigitalOcean

In this tutorial you will learn how to configure the Cloudflare CDN for your Sail-powered WordPress site, for better global web performance.

If you like Sail, don't forget to give us a star on GitHub!

What is Cloudflare?

Cloudflare is one of the largest content delivery networks (CDN) with over 250 locations worldwide. Regardless of where your WordPress server is located, Cloudflare caches your site's content at their edge locations, delivering it much quicker the next time it is accessed.

Cloudflare offers free plans, which have somewhat limited functionality, but will suffice for most use cases. Paid plans will get you more features and slightly better performance, if you can afford it.

Create a new Sail project

Create a new WordPress project with Sail CLI:

sail init

After the provisioning is successful, note down the hostname of your server. You will use this when configuring Cloudflare. Add the desired domain to your new WordPress install using Sail:

sail domain add example.org www.example.org

You do not need to point your domain to DigitalOcean at this time. It should instead be pointed to Cloudflare as explained in the next steps.

Create Cloudflare account

Cloudflare works as a reverse-proxy. This means you have to point your domain to Cloudflare's servers, and provide the origin host name or IP address to Cloudflare.

Create a free Cloudflare account and add your domain name following the on-screen instructions. You will need to change your domain nameserver records (at your domain registrar) to point to Cloudflare.

When it comes to DNS configuration, if you have existing A or CNAME records for the domains/subdomains you wish to point to your Sail server, you'll need to remove them first. Then you'll need to add a CNAME record for every domain name and subdomain you wish to point to your site. The target for these records should be the Sail hostname from the provisioning step earlier.

For example:

example.org IN CNAME b539970d8c935a51.justsailed.io
www.example.org IN CNAME b539970d8c935a51.justsailed.io

If you prefer, you could also use A records and point to your Sail server by IP address instead of the hostname. You can obtain the IP address by running sail info in your Sail project directory.

Make sure the "Proxy status" setting is set to Proxied. This will tell Cloudflare to proxy all traffic for these domains through their CDN.

SSL/TLS and primary domain

DNS changes may take a few hours to propagate, Cloudflare will usually send you and e-mail when everything is ready. After the traffic is being proxied from Cloudflare to your DigitalOcean server, you could request an SSL/TLS certificate with Sail:

sail domain make-https example.org www.example.org

And set it primary, like so:

sail domain make-primary example.org

After the certificate has been issued and installed, you may instruct Cloudflare to use the Full (strict) mode for more secure communication between the CDN and your DigitalOcean server.

Verifying your configuration

You could use a tool such as WebPageTest to verify that your content is being served quickly from various locations around the world.

If you need assistance with your WordPress site performance, please refer to our getting help section.