Visit AnalyticsUser Manual Visit Visit Analytics →
Reference and help

Cloudflare, proxies and load balancers: get the real visitor IP

If every visitor seems to have the same IP address, or your own address is wrong, your website sits behind a proxy. This page shows how to fix it.

The problem

PHP reports the address of whoever connects directly to the server. Behind Cloudflare, nginx used as a proxy, a CDN or a load balancer, that is the proxy, not the visitor. The real address is passed in a header.

The setting

Open Settings → Tracking → Advanced → Where to read the visitor IP:

OptionUse when
Automatic (connection address)Normal hosting. If the connecting address is a private network address (a proxy on the same network), VisitAnalytics automatically looks at CF-Connecting-IP, X-Real-IP and X-Forwarded-For, in that order.
Cloudflare (CF-Connecting-IP)Your site is behind Cloudflare.
X-Real-IPnginx or another proxy sets this header.
X-Forwarded-ForMost load balancers; the first valid address of the list is used.

The same tab shows Detected IP and the raw connection address (REMOTE_ADDR) to help you check the result. Open the page from your own device: the detected IP must be your real address.

Only choose a header that your proxy really sets. If your website is reachable directly (not only through the proxy), anybody could send a fake header and pretend to be another address. Keep Automatic when you are not behind a proxy.

Country behind Cloudflare

When Cloudflare sends CF-IPCountry, VisitAnalytics uses it, even for IPv6 visitors. Make sure "IP Geolocation" is enabled in the Cloudflare network settings (it is by default).

Cloudflare caching

If you use the Cloudflare rule "Cache Everything" for HTML pages, those pages are served without running PHP and cannot be tracked. Exclude pages that you want to count from that rule, or use the default caching that stores only static files. See Troubleshooting: no visits recorded, wrong IP, empty reports.

Last updated