Skip to main content
To proxy CrispStats with Caddy, add one handle_path block for /k3x9qe/* to your site in the Caddyfile. It rewrites the request to /p/…, removes the Cookie and Authorization headers and passes it to https://in.crispstats.com. Then point the script tag at the path with data-api, so ad blockers that stop known analytics hosts see a request to your own domain. The dashboard’s Tracking code tab has no Caddy example yet. This block follows the same rules as the other hosts, and the setup check below confirms it. Use your own path instead of /k3x9qe: Settings, Tracking code, Proxy through your own domain proposes one for your site. See the proxy overview for how the path, the check and signing work on every host.

Set up the proxy

1

Add the block to your site

Caddyfile
handle_path strips /k3x9qe from the path, rewrite puts /p in front and keeps the query string, so /k3x9qe/check?k=… reaches https://in.crispstats.com/p/check?k=…. Recent Caddy versions set the Host header for an HTTPS upstream on their own; the header_up Host line keeps older versions working. Reload Caddy with caddy reload.
2

Behind a load balancer or CDN, trust it

Caddy sets X-Forwarded-For to the address that connected to it, and ignores the incoming value unless the sender is listed in trusted_proxies. If Caddy sits behind a load balancer or CDN, add its address ranges to trusted_proxies in the global servers options, or every visit looks like it comes from one address.
3

Point the script tag at the path

src loads the script from your domain, and data-api sends events and visitor id requests to the same path:
data-api is required. Without it the script sends events to /e on your own domain, and those requests fail.
4

Run the setup check

Open the check through your proxy, in a browser, on your own site:
Look for "proxied": true, "visitorAddressForwarded": true and "cookiesForwarded": false. The proxy overview explains every field.

What this block forwards

Unlike the nginx example, reverse_proxy passes request headers on by default, so the block removes the two that must never reach a third party: Cookie and Authorization. The collector needs only content-type, user-agent, accept-language, referer, origin, if-none-match and the visitor’s address. If you want Caddy to send nothing else, remove more headers with further header_up -Name lines. Caddy also adds X-Forwarded-Proto and X-Forwarded-Host, which name your own site, not the visitor. See what a proxy forwards.

Visitor address and location

The collector takes the first public address in X-Forwarded-For, uses it for the daily visitor hash and your excluded IP addresses, then discards it. Caddy does not know where the visitor is, so the collector looks the country, region and city up from that address itself, as with nginx. See location.

Sign the requests (optional)

Signing proves a forwarded request came from your proxy. Reveal the secret (cs_px_…) in Settings, Tracking code, Proxy through your own domain, Advanced: sign proxied requests. Start Caddy with it in the environment as CRISPSTATS_PROXY_SECRET and add this line inside reverse_proxy:
Caddyfile
{$CRISPSTATS_PROXY_SECRET} is read from the environment when Caddy loads the Caddyfile, so the secret stays out of the file. Reload, then look for "signed": true in the setup check. See sign proxied requests.

FAQ

Caddy does not accept a path in the upstream address. handle_path removes your prefix and rewrite adds /p, which gives the same result.
Caddy is behind something that it does not trust, so X-Forwarded-For carries that hop’s address. Add its ranges to trusted_proxies, reload, and check for "visitorAddressForwarded": true.
Yes. It asks /k3x9qe/id, which the same block forwards.

Next steps

Proxy overview

The path, the check, caching, limits and signing.

Proxy with nginx

The same rule for nginx.

Ad blockers

What a proxy recovers and what it does not.
Caddy details (handle_path stripping the prefix, rewrite changing path and query, no paths in upstream addresses, header_up -Name, the automatic Host for HTTPS upstreams since v2.11.0, X-Forwarded-For and trusted_proxies, and {$ENV} substitution) checked against https://caddyserver.com/docs/caddyfile/directives/reverse_proxy, https://caddyserver.com/docs/caddyfile/directives/handle_path and https://caddyserver.com/docs/caddyfile/concepts on 2026-11-23. This configuration was not run against the live collector while writing this page; the setup check is how you confirm it.
Last modified on November 26, 2026