Placing Piwik behind CloudFlare

Hi all,

I’m looking to place my Piwik subdomains behind CloudFlare. I’ve already got proxy_client_headers[] = “HTTP_CF_CONNECTING_IP” set in my config file so that’s not an issue.

I’m just wondering whether it’ll hurt my stats? I’m not talking about putting the websites that Piwik tracks onto CloudFlare, but the subdomain Piwik actually works on onto CloudFlare. Does this make sense?

I was thinking of doing it by placing a page rule so that anything going to http://stats.example.com/piwik.php doesn’t go through CloudFlare and goes straight to the server. Would this be okay?

Any help would be great.

This sounds OK! (also filter out piwik.js possibly?)

I was thinking about filtering that out, but then realised that was the main point I was going to switch that domain over to it.

I figured the only reason when I would really need to edit that is when I upgraded to a new version. When I need to do that, I can use CloudFlare’s tool to delete that file from their CDN. Does that sound appropriate?

I’m in the process of testing it now, if everything goes well I’ll write up a tutorial on my blog.

Sure, but all things “manual” are better avoided if you can…

Yeah, that’s a fair point. Is it possible to run a function by placing something in bootstrap.php when a upgrade happens then?

For example, I could run the commands below once a upgrade is complete to remove the file from CloudFlare’s cache.

curl https://www.cloudflare.com/api_json.html
-d ‘a=zone_file_purge’
-d ‘tkn=an_api_token’
-d ‘email=sample@example.com’
-d ‘z=example.com
-d ‘url=http://stats.example.com/piwik.js’

curl https://www.cloudflare.com/api_json.html
-d ‘a=zone_file_purge’
-d ‘tkn=an_api_token’
-d ‘email=sample@example.com’
-d ‘z=example.com
-d ‘url=http://stats.example.com/style.css’