# Proxy the script through your own server

Forward /js/script.js and /api/event with nginx, Caddy, Next.js rewrites or Express, and the location and rate-limit trade-offs the managed proxy avoids.

You can also forward two paths of your own website to SuprAnalytics: `/js/script.js` (the script) and `/api/event` (where it sends events). The script sends events to the host it was loaded from, so once both are forwarded, nothing else changes.

> **Prefer the managed proxy**
>
> Through your own proxy, SuprAnalytics sees your **proxy's address** for every visitor, not the visitor's. Locations fall back to the browser's timezone (country only), and the per-IP rate limit (120 hits a minute) applies to all your traffic together, so a busy website gets `429`s. Cookieless mode also can't tell visitors apart. The [managed proxy](https://supranalytics.app/docs/managed-proxy.md) has none of these problems.

Next.js:

```
// next.config.js
module.exports = {
  async rewrites() {
    return [
      { source: "/js/script.js", destination: "https://supranalytics.app/js/script.js" },
      { source: "/api/event", destination: "https://supranalytics.app/api/event" },
    ];
  },
};
```

nginx:

```
location = /js/script.js {
    proxy_pass https://supranalytics.app/js/script.js;
    proxy_set_header Host supranalytics.app;
    proxy_ssl_server_name on;
}
location = /api/event {
    proxy_pass https://supranalytics.app/api/event;
    proxy_set_header Host supranalytics.app;
    proxy_ssl_server_name on;
}
```

Caddy:

```
yourdomain.com {
  handle /js/script.js {
    reverse_proxy https://supranalytics.app {
      header_up Host {upstream_hostport}
    }
  }
  handle /api/event {
    reverse_proxy https://supranalytics.app {
      header_up Host {upstream_hostport}
    }
  }
  # … the rest of your site
}
```

Express:

```
// npm install http-proxy-middleware
const { createProxyMiddleware } = require("http-proxy-middleware");

app.use(
  createProxyMiddleware({
    target: "https://supranalytics.app",
    changeOrigin: true,
    pathFilter: ["/js/script.js", "/api/event"],
  }),
);
```

Then load the script from your own domain:

```
<script defer supr-website-id="YOUR_WEBSITE_ID" supr-domain="yourdomain.com" src="/js/script.js"></script>
```

If `/api/event` is taken on your website, forward another path and point the script at it with `supr-api="/your/path"`.

## Live chat

With [live chat](https://supranalytics.app/docs/live-chat.md) on, the chat widget still loads from SuprAnalytics's own address (`/js/chat.js`), not through your proxy.

---

This page on the web: https://supranalytics.app/docs/own-proxy
Every documentation page: https://supranalytics.app/docs.md
