This tutorial walks through the process of setting up a Cloudflare CDN combination with KeyCDN. Cloudflare is different than most conventional CDNs in that your complete site is delivered via them whereas with a normal CDN, only the static content is delivered and via the CDN. When Cloudflare is used in combination with a CDN, it acts as a proxy for websites by sitting in between the CDN servers and the end user.
Cloudflare is also a free DNS hosting provider which means if you are using them as a DNS hoster, any DNS changes (such as adding a Zonealias) must be made through the Cloudflare DNS manager.
How To Use a Cloudflare CDN Setup
Using a Cloudflare CDN combination with KeyCDN is easy and can be done in just a few steps.
- Create a Pull Zone within the KeyCDN dashboard
- To use a Zonealias, follow the instructions in our Create a CNAME record in Cloudflare guide. Otherwise, there is nothing that needs to be modified within Cloudflare and the zone url (e.g lorem-1c6b.kxcdn.com) can be used.
- Use either the Zonealias url
cdn.example.comor the KeyCDN zone url
lorem-1c6b.kxcdn.comfor CMS, Framework, or custom CDN integration purposes
That’s it! Now your website is using a Cloudflare CDN combination, thus allowing you to use the features from both services in unison.
Other Cloudflare CDN Considerations
Cloudflare adds a Set-Cookie header to domains that are routed through Cloudflare’s system. These cookies can be seen by running a
curl -I example.com command from the terminal.
curl -I https://example.com/ HTTP/1.1 200 OK Server: cloudflare-nginx Date: Thu, 10 Dec 2015 14:46:10 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Set-Cookie: __cfduid=d43b3b2852bb7399a3191473c62d071181449758769; expires=Fri, 09-Dec-16 14:46:09 GMT; path=/; domain=.example.com; HttpOnly Last-Modified: Fri, 04 Dec 2015 20:06:15 GMT ETag: W/"13c354-4dbd-526180a2fb568" Vary: User-Agent CF-RAY: 2529bcd81a0f3024-YYZ
Files with cookies cannot be cached which means that if the cookie remains present in the file, it will not be delivered via the CDN. To solve this issue, the Cache Cookies and Strip Cookies options should be enabled in your zone’s advanced features page within the KeyCDN dashboard.
Cache Cookies will ignore the cookie and will force the edge server to cache the file. Strip Cookies actually removes the cookie from the header, therefore the client will not see the Set-Cookie response header. Both of these options are enabled by default in KeyCDN and it is recommended to enable Strip Cookies if Cache Cookies is enabled.
How Does Using a Cloudflare CDN Combination Help?
Using a Cloudflare CDN combination can offer many improvements to a website. Since Cloudflare is based on a freemium model, there are many features that are not available to users without paying a higher price. Using Cloudflare in conjunction with KeyCDN provides users with many additional features such as:
- Origin shield
- Secure token
- Let’s Encrypt support
- Push zones
- Wildcard subdomains
- Unlimited upload sizes
- Real-time analytics
As can be seen, there are many benefits to implementing a traditional CDN with Cloudflare, thus providing more features and flexibility for the user.