Visitor IPs show at 127.0.0.1 when using load-balanced Varnish front-end servers

Hello,

I’m trying to figure out why visitor IPs show as 127.0.0.1 when I enable Varnish on my Piwik stats web server running nginx and Varnish. Data is collected via the piWiki Analytics plugin for Wordpress. My Wordpress blog sits upon two VPSes which are load balanced and each run nginx and Varnish caching server on top of Debian Squeeze (all standard packages from Squeeze). My Piwik server also runs Debian Squeeze, Varnish and nginx.

Once everything was set-up, the correct IPs seem to show up in the visitor information within Piwik, but then subsequent requests started showing up as 127.0.0.1. I then disabled Varnish on the Piwik server and tested a few visits and the correct IP now shows up.

Is Varnish across all three servers getting Piwik confused? On another Piwik install (a single VPS with Debian Squeeze, Varnish, nginx and where Piwik is installed on the same VPS rather than separately in my own case) Piwik seems to be processing IPs correctly.

Any ideas? I’m happy to live without Varnish on my stats server, but curious to know what’s happening.

Thanks,

Martyn

Probably caused by Varnish setting IP in another header that you can configure piwik to read; Installation - Analytics Platform - Matomo

You need to configure varnish to pass thru the client’s IP address. Refer to the varnish docs.

Then you need to configure Piwik to recognize the http header injected by varnish and ignore the IP addresses of any servers between the public facing IP address and your piwik server. Refer to Installation - Analytics Platform - Matomo

Indeed, the following lines in nginx.conf do the trick nicely straight out of Squeeze’s nginx install:

set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;

nginx will then start logging the correct IP rather than 127.0.0.1.

Thanks folks :slight_smile:

Regards,

Martyn