Skip to content

Send the visitor IP in a header Cloudflare won't rewrite - #49

Merged
dubsector merged 1 commit into
mainfrom
visitor-ip-header
Aug 2, 2026
Merged

Send the visitor IP in a header Cloudflare won't rewrite#49
dubsector merged 1 commit into
mainfrom
visitor-ip-header

Conversation

@dubsector

Copy link
Copy Markdown
Owner

Every visit was landing in Matomo as the same private address (the proxy in front of it), so no visitor was distinguishable by IP and geolocation was a fallback guess.

proxy_client_headers[] = HTTP_X_FORWARDED_FOR was configured correctly on the Matomo side. The problem is upstream of that: the tracking subrequest leaves the Worker, crosses Cloudflare's edge again to reach the tunnel in front of Matomo, and the edge manages X-Forwarded-For — it rewrites the header to the connecting IP of its own leg, discarding what we set. By the time Matomo reads it, the visitor IP is gone.

/api/whoami was unaffected because it reads CF-Connecting-IP off the inbound request inside the Worker, with no proxy chain in between — which is why the site could display an IP it apparently couldn't log.

Switches to X-Visitor-IP, which Cloudflare has no handling for and passes through untouched.

Matomo side

[General]
proxy_client_headers[] = "HTTP_X_VISITOR_IP"

The existing X-Forwarded-For and proxy_ips entries can stay; they're just no longer load-bearing.

The tracking subrequest goes back out through Cloudflare's edge to reach
the tunnel in front of Matomo, and the edge rewrites X-Forwarded-For to
the connecting IP of that leg, so the visitor IP never survived the trip.
Every visit was logged as the proxy in front of Matomo, which also meant
no real geolocation and every visitor sharing one address. A custom
header isn't managed by the edge and arrives intact.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 2, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
terminal 481d894 Commit Preview URL

Branch Preview URL
Aug 02 2026, 04:19 AM

@dubsector
dubsector merged commit a6bc4b3 into main Aug 2, 2026
5 checks passed
@dubsector
dubsector deleted the visitor-ip-header branch August 2, 2026 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant