Varnish IP forwarding to apache and nginx
When you install varnish-cache on your server, you will notice that the IP your backend receives is always your localhost (IPv4 127.0.0.1, IPv6 ::1).
That’s a problem for different cases:
- The log doesn’t contain IP information (e.g. if you use an analytic tool like webalizer that scans the log for unique users)
- Local statistic tools (like piwik) gets confused
- You can’t use the PHP variable $_SERVER[‚REMOTE_ADDR‘] because it always returns 127.0.0.1
To fix this here’s the solution for apache and nginx webservers: