May 3, 2013

f Comment

Why is My CloudFlare CDN Not Working?

Amazon If you just started using a CDN such as Cloudflare or Google PageSpeed Service you may come across some confusions. Rest assured this article will help you unravel the mysteries.

Question
I am using CloudFlare as a CDN for my website but how come my origin web server log still shows HTTP requests when I go to my website? I am thoroughly confused.

To answer your questions walk through the things to check below. Let's assume your website is https://cppprogramming.chtoen.com/

Does your URL have a query string or a URL parameter?
In other words does your look like https://cppprogramming.chtoen.com/?param=1&param2=abc? As of 2013/5/10 CloudFlare does not cache URLs with query strings. In my page rule setting I have 'Cache everything' but CloudFlare wouldn't cache URLs with URL parameters. I have no idea why.

Are you seeing incorrect HTTP header?
Are you seeing incorrect HTTP header in the response even thought you've configured CloudFlare correctly? For example say you configure your server to return HTTP header Cache-Control:max-age=31536000 to mean one year CDN cache expiration and you configure CloudFlare's Browser cache expire TTL to 30 minutes.

However when you hit your website you see Cache-Control:max-age:31536000 in the HTTP response header. This is incorrect behavior. This is due to CloudFlare caching your old response header.

The solution is simple: go to CloudFlare settings and purge cache and try again. If it doesn't work let me know.

Are you sure you are caching your site?
In CloudFlare if you do not add any page rule then CloudFlare would only cache static resources per https://support.cloudflare.com/entries/22037282-What-file-extensions-does-CloudFlare-cache-for-static-content-.

CloudFlare applies to these static resources the settings you have listed in Performance Settings tab in CloudFlare settings section.

The following is this list at the time of the writing:

CloudFlare caches the following types of static content by extension for all account types by default:

css
js
jpg
jpeg
gif
ico
png
bmp
pict
csv
doc
pdf
pls
ppt
tif
tiff
eps
swf
midi
mid
ttf
eot
woff
svg
svgz
webp
docx
xlsx
xls
pptx
ps

If you'd like CloudFlare to cache all your pages simply create a page rule with URL set to https://cppprogramming.chtoen.com/*.

Read my post on The Best Configurations for CloudFlare CDN for a complete tutorial in this respect.

How do you know if CloudFlare is working?
CloudFlare caches a resource only when that specific resource is requested by someone (usually including search engine crawlers). To know whether CloudFlare is using its cache to serve a webpage requested by you, use Chrome or Firefox to go to https://cppprogramming.chtoen.com/ with their respective web developer toolbar opened.

You should see the following header in the HTTP response:

CF-Cache-Status: HIT
or

CF-Cache-Status: MISS
If you see either of these headers it means CloudFlare is working! HIT means CloudFlare used its cache to serve the request. MISS means CloudFlare did not use its cache to serve the request; instead CloudFlare goes to your origin server to get the webpage and forward it to the client browser.

If you go to the same page twice the latter should always give you CF-Cache-Status: HIT because you would've given CloudFlare the chance to cache the page in your first try. If not, read my post on The Best Configurations for CloudFlare CDN to know exactly how CloudFlare caches your website.

Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael