> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Proxy CrispStats with nginx

> Serve the CrispStats script and events from your own domain with one nginx location block that forwards only safe headers and the visitor's address.

To proxy CrispStats with nginx, add one `location` block for `/k3x9qe/` inside your site's `server` block that passes requests to `https://in.crispstats.com/p/`, then point the script tag at the path with `data-api`. Ad blockers that stop known analytics hosts then see a request to your own domain, so those visitors are counted.

The block turns off nginx's default of passing every request header and sets only the ones analytics needs, so your visitors' cookies never leave your server. Use your own path instead of `/k3x9qe`: **Settings**, **Tracking code**, **Proxy through your own domain** proposes one for your site. See [the proxy overview](https://docs.crispstats.com/tracking/proxy.md) for how the path, the check and signing work on every host.

## Set up the proxy

**1. Add the location block**

Add it inside the `server` block of your site, then reload nginx.

```nginx nginx.conf theme={"theme":{"light":"github-light","dark":"github-dark"}}
location ^~ /k3x9qe/ {
  proxy_pass https://in.crispstats.com/p/;
  proxy_ssl_server_name on;
  proxy_set_header Host in.crispstats.com;

  # Only these headers go upstream: never your visitors' cookies or authorization.
  proxy_pass_request_headers off;
  proxy_set_header Content-Type $content_type;
  proxy_set_header User-Agent $http_user_agent;
  proxy_set_header Accept-Language $http_accept_language;
  proxy_set_header Referer $http_referer;
  proxy_set_header Origin $http_origin;
  proxy_set_header If-None-Match $http_if_none_match;
  proxy_set_header X-Forwarded-For $remote_addr;
}
```

**2. Behind a load balancer, set the real address first**

If nginx sits behind a load balancer or CDN, configure `real_ip_header` and `set_real_ip_from` first, so `$remote_addr` is the visitor and not the load balancer. Otherwise every visit looks like it comes from one address, and visitors merge.

**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:

```html theme={"theme":{"light":"github-light","dark":"github-dark"}}
<script
  defer
  data-site="cs_pk_xxxxxxxx"
  data-domains="example.com"
  data-api="/k3x9qe"
  src="/k3x9qe/d.js"
></script>
```

`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:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
https://example.com/k3x9qe/check?k=cs_pk_xxxxxxxx
```

Look for `"visitorAddressForwarded": true` and `"cookiesForwarded": false`. The [proxy overview](https://docs.crispstats.com/tracking/proxy.md#check-it-works) explains every field.

## Visitor address and location

nginx passes the visitor's address in `X-Forwarded-For` from `$remote_addr`. The collector uses it for the daily visitor hash and your excluded IP addresses, then discards it. nginx does not know where the visitor is, so the collector looks the country, region and city up from that address itself. If your setup knows the location (for example from a CDN header), you can set `x-crispstats-country`, `x-crispstats-region` and `x-crispstats-city` yourself, and those win. See [location](https://docs.crispstats.com/tracking/proxy.md#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**, and add this line to the `location` block with the secret in place of the placeholder:

```nginx nginx theme={"theme":{"light":"github-light","dark":"github-dark"}}
proxy_set_header x-crispstats-proxy-secret "<your proxy secret>";
```

Reload nginx, then look for `"signed": true` in the setup check. Keep the config file readable only by the accounts that need it. See [sign proxied requests](https://docs.crispstats.com/tracking/proxy.md#sign-proxied-requests).

## FAQ

> [accordion] Why proxy\_pass\_request\_headers off?
>
> By default nginx passes every request header upstream, including cookies and authorization. Turning it off and setting only the listed headers by hand keeps them out.

> [accordion] Why ^\~ on the location?
>
> `^~` makes this prefix match win over regular-expression locations, so a rule for `.js` files elsewhere in your config does not catch `/k3x9qe/d.js`.

> [accordion] Every visitor looks like one visitor. Why?
>
> The collector sees your load balancer's address. Set `real_ip_header` and `set_real_ip_from`, reload, and check for `"visitorAddressForwarded": true`.

## Next steps

> [card] [Proxy overview](https://docs.crispstats.com/tracking/proxy.md)
>
> The path, the check, caching, limits and signing.

> [card] [Proxy with Caddy](https://docs.crispstats.com/tracking/proxy/caddy.md)
>
> The same rule for Caddy.

> [card] [Exclude IP addresses](https://docs.crispstats.com/tracking/exclude-traffic.md#exclude-ip-addresses)
>
> Compared with the forwarded visitor address.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.