Plausible counts visitors via a hash of IP address, user agent, domain and a daily salt. Behind a reverse proxy every request comes from the proxy. If the proxy doesn't take the real IP from X-Forwarded-For, all your visitors become one.
Symptom
cd ~/plausible/ce
T=$(cat ~/plausible/tag04-start)
docker compose exec -T plausible_events_db clickhouse-client -d plausible_events_db \
--query "select count(), uniqExact(user_id) from events_v2
where name = 'pageview' and timestamp >= '$T'"
3 1
Three pageviews from three different IPs, one visitor. All events arrive and are counted – only the user_id is the same for all of them.
Diagnosis
Send three visits with different IPs (X-Forwarded-For): all are counted ("gezählt"). Then compare pageviews and distinct user_id values in ClickHouse. If the visitor count is one, Plausible only sees the proxy's address.
cd ~/plausible/pw
UA="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"
UA="$UA Chrome/140.0.0.0 Safari/537.36"
I=mcr.microsoft.com/playwright:v1.65.0-noble
for ip in 203.0.113.30 203.0.113.31 203.0.113.32; do
docker run --rm --network host --user "$(id -u):$(id -g)" -e HOME=/tmp -e ECHT=1 \
-e UA="$UA" -e IP=$ip -v ~/plausible/pw:/pw -w /pw \
$I node besuch.js https://itdrills.com/books/ | tail -1
done
<- 202 gezählt
<- 202 gezählt
<- 202 gezählt
Causes
X-Forwarded-ForThe proxy overwrites the client IP
Caddy only trusts an incoming X-Forwarded-For if the request comes from a trusted proxy. Otherwise it replaces the value with the address it sees itself. That's correct – otherwise any visitor could make up an IP.
Cloudflare / LBUpstream proxy not trusted
Behind Cloudflare or a load balancer this means: every visitor comes from the proxy. Without trusted_proxies (set_real_ip_from in nginx) Plausible only sees Cloudflare.
Fix
cd ~/plausible/proxy
{ printf '{\n\tservers {\n\t\ttrusted_proxies static 127.0.0.1/8 ::1\n\t}\n}\n\n'
cat Caddyfile; } > Caddyfile.neu
mv Caddyfile.neu Caddyfile
docker exec caddy caddy validate --config /etc/caddy/Caddyfile 2>&1 | tail -1
docker exec caddy caddy reload --config /etc/caddy/Caddyfile 2>/dev/null; echo "rc=$?"
Valid configuration
rc=0
Don't: Opening trusted_proxies to every address. Then any visitor can claim any IP via X-Forwarded-For.
Plausible Analytics, day 4: Caddy with HTTPS in front, script and events through your own domain and real visitor IPs behind the proxy.
Go to day 4 →
FAQ
How do I check that the fix works?
Send three visits with different IPs again and run the same query. In the course it then shows three pageviews and three visitors.
What's the nginx equivalent?
real_ip_header X-Forwarded-For; set_real_ip_from <range>; and when passing the request on, proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Does this affect shields too?
Yes. An IP block applies to the IP Plausible sees. Without trusted_proxies Plausible would only see the VM itself, and the block would never match.