Plausible Analytics, my privacy-friendly analytics platform of choice, supports locations. When I migrated to my current stack a little over a month ago, I lost support for it, and didn’t notice.
Let’s remind ourselves of my surprisingly popular post about how I deploy static sites. In it I detail the general Caddyfile
structure I use, and it’s not a whole lot at all, mostly centering around doing rewrites for a couple of paths so I can proxy to Plausible via my domain.
This setup has worked just fine for me in the past. I’ve hosted my sites on several different PaaS platforms, and have used both cloud and self-hosted deployments of Plausible as well. This is the first time just the location data was missing.
I went on a bit of a hunt tonight and figured it out. This is where the relative complexity of my setup got a bit annoying, since I have Traefik proxying to the Docker container with Caddy, which is then proxying to Plausible. Exactly what was getting lost and where could’ve had multiple answers.
After trying a bunch of different settings for Traefik, I tried a bunch of different things with headers in Caddy, and the missing magic turned out to be this line:
header_up X-Forwarded-For {http.request.header.X-Forwarded-For}
It goes next to—e.g., below—the existing header
directive, and it forwards the IP address of the original request to Plausible, instead of one of the internal addresses of the server/container/whatever. This unlocks location data with no other changes needed.
A combination of Plausible’s Nginx proxying guide and Caddy’s reverse_proxy
directive docs were quite helpful, and thanks to Tyrel for pointing me in the general direction of forwarding headers.
If you’ve got a similar setup and the same problem, hope this helps!
Thanks for reading! You can keep up with my writing via the feed or newsletter, or you can get in touch via email or Mastodon.