Use Cloudflare as a traditional CDN
Integrating Cloudflare into our cPanel servers has proven very popular over the years, however occasionally some customers do not require all of the features of Cloudflare and just want to use it more like a traditional CDN where static objects are accessed via a different domain or subdomain.
We have been spending time working out how customers can get the best of Cloudflare as a CDN and have managed to get this solution working with a couple of slight workarounds. This allows static objects to be included using the Cloudflare enabled subdomain while keeping the main website handled by the hosting server.
- cPanel based hosting package with Clook Internet
- Working email address
- A domain with DNS delegated to our nameservers
1. Log in to the cPanel control panel and head to “Cloudflare”
2. Sign up to Cloudflare using your email address. If you already have a Cloudflare account, log in to it when prompted
3. Go to cPanel -> Subdomains and add a new addon domain (cdn.yourdomain.com) and ensure the DocumentRoot is set the same as the main website (usually public_html)
4. Once the subdomain has been added we need to apply a workaround to get Cloudflare to recognise it. Go to the Advanced DNS Editor of cPanel which shows a list of all DNS records for your domain. Click the Edit link next to the record for the new subdomain which should be showing an A record and a numerical IP address.
Change the record to a CNAME type and put “cdn.domain.com.cdn.cloudflare.net.” into the CNAME field replacing “domain.com” with your actual domain name (without the www.).
5. Go back to the cPanel main page and click the Cloudflare link. When clicking the Manage button under “My Websites” there should be a line for each subdomain along with your main domain. Make sure the image showing the Cloudflare status is greyed out for the main domain (www) but coloured orange for the cdn.domain.com subdomain.
6. Wait for an hour or two for the DNS records to update around the internet then you should be able to use “cdn.domain.com” (replace domain.com with your actual domain) as the domain from which to call static objects. This can be used as the CDN domain if you use the W3 Total Cache plugin for WordPress to improve performance.