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

# Proxy Trfyx through Nginx

> Proxy Trfyx analytics through Nginx by adding two reverse-proxy locations.

You can proxy the Trfyx tracker and event endpoint through Nginx so requests stay on your domain.

<Steps>
  <Step title="Add Nginx configuration">
    Add two locations to your server block: one for the tracker and one for event collection.

    ```nginx nginx.conf theme={"dark"}
    location = /script.js {
        proxy_pass https://app.trfyx.com/script.js;
        proxy_set_header Host app.trfyx.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_cache_valid 200 1y;
        add_header Cache-Control "public, max-age=31536000";
    }

    location = /api/events {
        proxy_pass https://app.trfyx.com/api/events;
        proxy_set_header Host app.trfyx.com;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_pass_request_body on;
    }
    ```

    If `/api/events` is already used by your application, choose another public path and configure `data-api-url` accordingly.
  </Step>

  <Step title="Update the tracker">
    Update the tracker snippet to use the proxied path:

    ```html index.html theme={"dark"}
    <script
      defer
      data-website-id="YOUR_TRFYX_PROJECT_ID"
      data-domain="yourdomain.com"
      src="/script.js"
    ></script>
    ```
  </Step>

  <Step title="Test and reload">
    Validate the configuration and reload Nginx:

    ```bash Terminal theme={"dark"}
    sudo nginx -t
    sudo systemctl reload nginx
    ```
  </Step>

  <Step title="Verify installation">
    Open your production site and verify requests in your browser Network panel. Confirm both `script.js` and `/api/events` use your domain, then check that activity shows in Trfyx.
  </Step>
</Steps>

<Warning>
  Correct `X-Real-IP` and `X-Forwarded-For` handling is important for visitor location accuracy. If your site is behind another CDN or load balancer, configure the complete trusted proxy chain.
</Warning>

## Next steps

<CardGroup cols={2}>
  <Card title="Proxy setup" icon="signs-post" href="/proxy-guide">
    Read the full proxy setup guide
  </Card>

  <Card title="Managed Proxy" icon="shield-halved" href="/managed-proxy">
    Let Trfyx manage the proxy for you
  </Card>

  <Card title="Goals" icon="bullseye" href="/goals">
    Start tracking goals with Trfyx
  </Card>

  <Card title="Troubleshooting" icon="life-ring" href="/troubleshooting">
    Fix common proxy issues
  </Card>
</CardGroup>


## Related topics

- [Proxy Trfyx through your domain](/proxy-guide.md)
- [Proxy Trfyx through PHP](/php-proxy.md)
- [Proxy Trfyx through Express](/express-proxy.md)
- [Proxy Trfyx through Flask](/flask-proxy.md)


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