---

title: Run knownprint from your domain
description: Why knownprint's script and its requests go through a /kp/ path on your own site, what the proxy rule does, what you receive with your account, and how to fix a rule that does not work.
---

knownprint runs from your own domain. Your web server forwards one path of your site, `/kp/`, to knownprint, and your pages load the script from that path. The script, its identification requests and the cookie knownprint keeps all belong to your site. If your site sends a Content Security Policy, it must also allow the knownprint host your account names ([Content Security Policy](/install/csp)).

This page explains what the proxy rule does and what it needs from you. The step by step recipes are on their own pages:

| Your server                           | Recipe                                         |
| ------------------------------------- | ---------------------------------------------- |
| nginx                                 | [Install on nginx](/install/nginx)             |
| nginx behind Cloudflare's proxied DNS | [Sites behind Cloudflare](/install/cloudflare) |
| Caddy                                 | [Install on Caddy](/install/caddy)             |

Once the rule works, add the script to your pages with [the browser agent](/install/browser).

## Why the script runs first party

Serving knownprint from your own domain gives you four things:

- **Requests that reach knownprint.** Content blockers and browser privacy features treat a request to your own domain as part of your site. A script or request on a third-party analytics or security hostname is far more often blocked, delayed or stripped of its cookies.
- **A cookie your server sets.** knownprint's cookie is set by the answer your own server returns, on your own host, so it is your site's own first-party cookie. [Privacy](/privacy#the-first-party-cookie-and-the-storage-token) lists its attributes.
- **The visitor's real address.** Your server sees the visitor's connection and passes its address on, signed with your proxy secret. Without that, knownprint would see only your server's address. See [The visitor's address](#the-visitor-s-address).
- **A simple Content Security Policy.** The script and its identification requests come from your own origin, so `'self'` covers them, beside the one knownprint host the policy lists. See [Content Security Policy](/install/csp).

## What the proxy rule does

The rule is a block of configuration you add to the server that terminates TLS for your site. For every request under `/kp/` it:

1. forwards the request to knownprint, at the address that comes with your account;
2. adds your proxy secret, the visitor's address and your site's hostname, so knownprint knows the request came through your server and from whom;
3. removes every cookie except knownprint's own, so your session cookies never leave your server;
4. sets the cache lifetime of each path, so the script is cached and identifications never are.

It also serves your disclosure file at `/.well-known/knownprint.json` from a file on your server.

The rule leaves the browser's own request headers, `Origin` among them, as the browser sent them, and passes knownprint's `Set-Cookie` back to the browser on the paths that set a cookie. Do not add rules of your own that remove or rewrite headers on `/kp/` paths.

Everything outside `/kp/` and the disclosure file is untouched: your site keeps working exactly as before.

## What you receive with your account

:::note Early access
knownprint is in early access and signup is not open yet ("Get early access" at [knownprint.com](https://knownprint.com)). The files and values below come with your account, and so does your knownprint contact, who answers questions about your setup.
:::

| What                | What it is                                                                                                                                                                                                                                                                                                    | Where it goes                                                              |
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| The proxy recipe    | The configuration files for your server: for nginx, a file for the `http` block, a file for your site's `server` block, a variant of that file for sites behind Cloudflare and an example of the secret file; for Caddy, one snippet. Your copy already names the knownprint address your server forwards to. | Your web server                                                            |
| A proxy secret      | 32 characters, issued for each environment. It proves that a request came through your server.                                                                                                                                                                                                                | Your web server only (a file for nginx, an environment variable for Caddy) |
| The disclosure file | `knownprint.json`, the machine-readable disclosure your server publishes.                                                                                                                                                                                                                                     | `/usr/local/share/knownprint/knownprint.json` on your web server           |
| A public key        | `pk_live_` or `pk_test_` and 32 characters                                                                                                                                                                                                                                                                    | Your pages ([the browser agent](/install/browser))                         |
| A secret key        | `sk_live_` or `sk_test_` and 32 characters                                                                                                                                                                                                                                                                    | Your backend ([verify in your backend](/install/server))                   |

You set two things in the recipe yourself: the proxy secret, and the three fields of the disclosure file that describe your business ([Privacy](/privacy#the-disclosure-file) lists them). The recipe sets everything else, including every header knownprint reads from your server. Keep the files as you received them, apart from the response headers the [nginx page](/install/nginx#step-6-repeat-server-wide-response-headers) tells you to repeat; a changed line can stop the rule working or let your own cookies through.

### The proxy secret

Each environment has its own proxy secret, so your test and live environments each have one. Use the secret of the environment whose public key your pages load: a staging site with a test key uses the test environment's secret.

Treat the proxy secret like a password:

- Keep it out of version control, logs, tickets and chat messages. Whoever holds it can send requests that knownprint takes as coming from your server, with any visitor address they choose.
- Store it only where the recipe says: a file readable by root and the nginx group, or an environment file readable only by root for Caddy.
- Rotate it if it may have leaked.

An environment can hold several proxy secrets at once, so you can rotate without downtime:

1. Create a new proxy secret with `POST /v1/keys` and the body `{"kind": "proxy_secret"}`, using a secret key with the `keys:manage` scope. The answer is `201` and carries the new value once, in `value`, with its `id`.
2. Put the new value in your server's configuration on every server that answers for your domain, then reload nginx ([step 2](/install/nginx#step-2-store-the-proxy-secret)) or restart Caddy ([Rotating the secret](/install/caddy#rotating-the-secret)).
3. Retire the old secret with `DELETE /v1/keys/{id}`, which answers `204`.

```bash
curl -X POST "$KNOWNPRINT_API/v1/keys" \
  -H "Authorization: Bearer $KNOWNPRINT_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind": "proxy_secret"}'
```

A new or retired secret takes effect within a minute. `GET /v1/keys` lists your proxy secrets with their ids and creation times, never their values. [API keys](/api/keys) documents the three routes.

## The paths under /kp/

Every request the script makes goes to a path under `/kp/` on the page's own origin. The rule forwards them all; you never need to list them in your own configuration, but they help when you read your logs.

| Path                                     | Method | What it is                                                                 | Cookies forwarded          | Cache lifetime                                                                                    |
| ---------------------------------------- | ------ | -------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------------------------------------------------- |
| `/kp/agent.js`                           | `GET`  | The loader your pages include with a script tag                            | None, and no cookie is set | `public, max-age=3600, s-maxage=60`: browsers keep it up to an hour, shared caches up to a minute |
| `/kp/a/{build}.js`, `/kp/a/{build}.s.js` | `GET`  | The script files the loader fetches, one name per release                  | None, and no cookie is set | `public, max-age=31536000, immutable`: each release has its own name, so a year is safe           |
| `/kp/c`                                  | `POST` | The start of each identification                                           | knownprint's cookie only   | `no-store`                                                                                        |
| `/kp/i`                                  | `POST` | The identification itself; its answer sets knownprint's cookie             | knownprint's cookie only   | `no-store`                                                                                        |
| `/kp/l/{request_id}`                     | `POST` | A follow-up route of the agent, which can update the stored event          | knownprint's cookie only   | `no-store`                                                                                        |
| `/kp/b/{request_id}`                     | `POST` | A follow-up route of the agent, which can update the stored event          | knownprint's cookie only   | `no-store`                                                                                        |
| `/.well-known/knownprint.json`           | `GET`  | Your disclosure file, served from your server's disk as `application/json` | Not forwarded              | Your server's default                                                                             |

Any other path under `/kp/` is forwarded too and answered `404` by knownprint. A `POST` to `/kp/l/` or `/kp/b/` can be answered `410`; that is normal and the script ignores it. [Agent routes](/api/agent) lists the status codes each route answers.

The script uses `/kp/` on the page's origin by default. If your site cannot give up that path, the script's `endpoint` option points it elsewhere ([The endpoint](/install/browser#the-endpoint)). The recipe you receive handles `/kp/` only, so a different path means a different recipe: ask your knownprint contact before you change it.

## Cookies

The rule passes exactly one kind of cookie to knownprint: knownprint's own first-party cookie. Every other cookie of your site, sessions, carts, consent records, analytics, stays on your server and never reaches knownprint. On the loader and the script files no cookie is forwarded at all, and any cookie in their answers is removed.

In the other direction, the answer to an identification sets knownprint's cookie through your server, on the page's own host, with `HttpOnly`, `Secure` and `SameSite=Lax`. Because the cookie is `Secure`, your pages must be served over `https`.

Two things on your side must leave the cookie alone:

- Nothing between the browser and knownprint may remove or rewrite the `Set-Cookie` header of `/kp/` answers: not your server's own rules, not a CDN, not a security product.
- Do not write cookie rules of your own for `/kp/` paths. The recipe already decides which cookie reaches knownprint, and a rule of yours could forward your own cookies or hold back knownprint's.

If your site has a "forget me" or account deletion flow, see [Forget this browser](/install/browser#forget-this-browser) and [Deleting a visitor's data](/privacy#deleting-a-visitor-s-data).

## Caching

The rule sets the cache lifetime of every `/kp/` answer, as the table above shows:

- The loader may be cached by browsers for an hour and by shared caches (your CDN) for a minute. Do not give it a longer lifetime: the loader names the current release of the script files, and a loader cached for too long can ask for a release that is no longer served, which makes `load()` fail with `load_failed`.
- The script files carry their release in their name and may be cached for a year.
- The identification paths are `no-store`: never cached anywhere.

If your CDN has a "cache everything" rule, a rule that overrides cache lifetimes, or a rule that minifies or rewrites JavaScript, exclude `/kp/` from it. The loader checks the integrity of the script files it fetches and refuses a copy that was changed on the way. [Sites behind Cloudflare](/install/cloudflare#what-to-set-in-cloudflare) shows the settings for Cloudflare.

## The visitor's address

knownprint needs the address of the visitor's connection: it is part of the event (`network.ip`), the network and location signals describe it, and it is the unit of the per-address [rate limits](/limits).

The rule sends the address your server sees for the connection, together with your proxy secret. knownprint accepts that address only from a request that carries a valid proxy secret of the page's environment. A request without it, or with a wrong or retired secret, is taken at face value: its address is the address that connected to knownprint, which is your server. Then:

- every event shows your server's address in `network.ip`;
- the network and location signals describe your hosting provider, not the visitor;
- all your visitors share one address in knownprint's per-address rate limits, so busy pages start to see `429 rate_limited`;
- a public key with allowed IP ranges refuses your visitors with `403 ip_not_allowed` whenever your server's address is outside those ranges.

To check, identify a browser on your site and read the event from your backend: `network.ip` must be the public address of the machine you browsed from, not your server's.

```bash
curl "$KNOWNPRINT_API/v1/events/$REQUEST_ID" \
  -H "Authorization: Bearer $KNOWNPRINT_SECRET_KEY"
```

[Events](/events) describes the rest of the event.

## Sites behind a CDN or a load balancer

The rule sends the address _your server_ sees. When a CDN or a load balancer stands in front of your server, that address is the CDN's or the load balancer's, unless your server is told to take the visitor's address from what the front end passes on. The address must be right before you go live.

- **Cloudflare with proxied DNS, in front of nginx.** Use the Cloudflare variant of the recipe, which takes the visitor's address from Cloudflare's header on connections from Cloudflare's ranges only. See [Sites behind Cloudflare](/install/cloudflare).
- **A load balancer or another CDN in front of nginx.** Configure nginx's real IP module in your `server` block, before the knownprint include, so that `$remote_addr` is the visitor's address. The example follows this list.
- **Caddy behind a CDN or a load balancer.** The Caddy snippet passes the address of the connection Caddy accepted. Run it on the server that receives visitors' connections directly, and ask your knownprint contact before you put a Caddy site behind another proxy.

For nginx behind a load balancer, trust only the addresses of your own front end:

```nginx title="server block, before the knownprint include"
# Your load balancer's addresses (example values from the documentation ranges).
set_real_ip_from 192.0.2.10;
set_real_ip_from 192.0.2.11;
# The header your load balancer writes the visitor's address into.
real_ip_header X-Forwarded-For;
real_ip_recursive on;
```

If your load balancer speaks the PROXY protocol, use `listen 443 ssl proxy_protocol;` and `real_ip_header proxy_protocol;` instead of the header. Never trust the header from every address: anyone could then send a request that claims any address, and it would reach knownprint signed with your proxy secret.

When several servers answer for your domain (behind a load balancer, or in several regions), every one of them needs the rule and the same proxy secret. When knownprint sends you a new version of the recipe, install it on all of them in the same change rather than one at a time over days.

## Other servers

The recipes cover nginx, nginx behind Cloudflare, and Caddy. If your site runs behind another server, a hosting platform's rewrites or an edge function, ask your knownprint contact before you write a rule of your own: the cookie filtering and the headers the recipe sets must be exactly right, and a rule that forwards your session cookies or loses the visitor's address is worse than none.

## Troubleshooting

| What you see                                            | Likely cause                                                                                                                                           | What to do                                                                                                                               |
| ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------- |
| `/kp/agent.js` answers `404` from your own server       | The rule is not in the `server` block that answers for this host, or the server was not reloaded                                                       | Check the include in the right `server` block (or `import knownprint` in the right Caddy site block), test the configuration and reload. |
| `/kp/` paths answer `502` or `504`                      | Your server cannot reach knownprint                                                                                                                    | Check that the upstream address in your copy of the recipe is unchanged and that your server may open outgoing connections to it.        |
| `load()` rejects with `load_failed` for every visitor   | The loader or the script files do not arrive intact: a CSP that blocks them, a CDN or optimiser that rewrites JavaScript, or a loader cached too long  | Check [Content Security Policy](/install/csp), exclude `/kp/` from rewriting and from cache overrides.                                   |
| `403 origin_not_allowed`                                | The page's origin is not on the public key's allowed origins, or a rule strips the `Origin` header                                                     | Add the exact origin to the key; remove any rule that touches headers on `/kp/`.                                                         |
| Every event shows your server's address in `network.ip` | The proxy secret is missing, wrong or retired, or the request did not go through the rule                                                              | Check the secret against your account, check that it belongs to the page's environment, and reload.                                      |
| Every event shows your CDN's or load balancer's address | Your server does not take the visitor's address from the front end                                                                                     | See [Sites behind a CDN or a load balancer](#sites-behind-a-cdn-or-a-load-balancer).                                                     |
| Many `429 rate_limited` answers on `/kp/c` or `/kp/i`   | All visitors appear under one address (one of the two rows above)                                                                                      | Fix the address first; see [Limits](/limits) for the limits themselves.                                                                  |
| `403 ip_not_allowed`                                    | The public key has allowed IP ranges and the address knownprint saw is outside them, often because it is your server's                                 | Fix the address, or the key's ranges ([API keys](/api/keys)).                                                                            |
| Returning visitors are rarely recognised                | knownprint's cookie does not survive: the page is not `https`, something removes `Set-Cookie` on `/kp/i`, or one of several servers forwards no cookie | Check the response headers of `/kp/i` in the browser's developer tools, and that every server runs the same recipe.                      |
| `410` answers on `/kp/l/...` or `/kp/b/...`             | A follow-up of the agent was not recorded                                                                                                              | Nothing: this is expected and harmless.                                                                                                  |
| `/.well-known/knownprint.json` answers `404` or `403`   | The file is missing or your server cannot read it                                                                                                      | Install it at `/usr/local/share/knownprint/knownprint.json`, readable by everyone (mode `0644`).                                         |

Server-specific errors, such as configuration test failures, are on the [nginx](/install/nginx#troubleshooting), [Caddy](/install/caddy#troubleshooting) and [Cloudflare](/install/cloudflare#troubleshooting) pages. When the rule works, continue with [the browser agent](/install/browser) and, before launch, [Go live](/install/go-live).
