Showing correct IP addresses while using CloudFlare

Hi.

I’ve trying to come up with a solution for this, but to no avail. I set up my site with CloudFlare, but now all my visitors in Piwik have CloudFlare’s IPs. I found this thread, and although I tried the suggested solution, I can’t seem to make it work. What I’ve done so far is copying the following lines to my config.ini.php:


[General]
; CloudFlare (CF-Connecting-IP)
proxy_client_headers[] = HTTP_CF_CONNECTING_IP

I’ve also tried uncommenting this line in global.ini.php but it’s still not working. Any ideas?

1 Like

Maybe there is already a [General] section in your config.ini.php ? in which case you add the proxy_client_headers[] = HTTP_CF_CONNECTING_IP

below the eixsting section
PS: it will only work for future requests /visits

Thanks for you reply. It was my bad, I forgot I was using the “piwik.php proxy script,” instead of the Javascript code, with this particular installation. Just for completion, if anyone’s trying to achieve the same, you just have to modify this line, in your piwik.php file:


$url = $PIWIK_URL."piwik.php?cip=".@$_SERVER['REMOTE_ADDR']."&token_auth=".$TOKEN_AUTH.'&';

Change to:


$url = $PIWIK_URL."piwik.php?cip=".@$_SERVER['HTTP_CF_CONNECTING_IP']."&token_auth=".$TOKEN_AUTH.'&';

I’m having the same issue and wasnt sure if I should revive an old thread on the same topic or start a new one.

My scenario is this:
my piwik server is on cloudflare + SSL. I have added to config:


proxy_client_headers[] = HTTP_CF_CONNECTING_IP

I have also added mod_cloudflare to apache.

My website is on a seperate server and also uses Cloudflare + SSL + the piwik tracker proxy. I have added mod_cloudflare to apache.

My piwik server does correctly log visitors, but all the visitors have a Cloudflare IP address. I have tried modifying the piwik.php file, however the code seems to have changed from the example mod posted by daat. only the last line in the code includes [REMOTE_ADDR]:


return arrayValue($_SERVER, 'REMOTE_ADDR');

I have changed this to:


return arrayValue($_SERVER, 'HTTP_CF_CONNECTING_IP');

but the visits still show Cloudflare IP’s… any ideas what to do to log the correct visitor IP?

should I start a new thread perhaps?

I thought it was correct to post in a thread with the same subject… should I be starting a new thread instead?

I’m a little stuck here guys - can’t even get a reply from premium support :slight_smile: is cloudflare really so problematic?

hi there,

Fyi: if you think you have found a bug, it’s usually more direct to create a bug report at: Issues · matomo-org/piwik · GitHub

In this case, can you check you’re using the latest version of the tracker proxy? tracker-proxy/piwik.php at master · matomo-org/tracker-proxy · GitHub

we added the support for CF and others few months back, you may need to update this piwik.php proxy file on your servers?

Matt,

thanks for the reply - I’m not sure if its a bug, hence my posting in a Cloudflare related thread.

I have checked the tracker proxy and it is the current version - thank you for the suggestion.

I’ve quite diligently searched the forum for information about the steps necessary to implement Piwik with Cloudflare, and as far as I can see I’ve done everything suggested:
install apache mod_cloudflare
modfied the piwik config file

I was unclear if the issue originates with the fact that both the piwik server AND the website being tracked are both on Cloudflare, if there is anything additional I need to do to account for this factor?

Create a file <?php var_dump($_SERVER); ?>

which entry from the array displays the correct IP address?

Thanks Matt,

These ones show the correct IP:
HTTP_X_FORWARDED_FOR
HTTP_CF_CONNECTING_IP
REMOTE_ADDR

I loaded a page on the site and looked in piwik console at the same time, and the pageload showed a Cloudflare IP address,

Does the fact that the array dump shows my IP correctly mean that the proxy tracker callhome to my Piwik server is where the CF IP is being introduced, due in some way to the fact the Piwik server itself is also on Cloudflare?

Thanks Matt,

These ones show the correct IP:
HTTP_X_FORWARDED_FOR
HTTP_CF_CONNECTING_IP
REMOTE_ADDR

I loaded a page on the site and looked in piwik console at the same time, and the pageload showed a Cloudflare IP address; I dont see any cloudflare addresses in the array dump data so I’m not sure where its coming from…

Does the fact that the array dump shows my IP correctly mean that the proxy tracker callhome to my Piwik server is where the CF IP is being introduced, due in some way to the fact the Piwik server itself is also on Cloudflare?