Nginx Proxy
Configure Nginx to proxy the usertrax script and events API through your domain.
Add proxy locations
Add these blocks inside your
serverblock in your Nginx config:# Proxy the usertrax tracking scriptlocation = /cvs.js {proxy_pass https://usertrax.io/cvs.js;proxy_ssl_server_name on;proxy_set_header Host usertrax.io;add_header Cache-Control "public, max-age=86400";}# Proxy the events endpointlocation = /api/usertrax/events {proxy_pass https://api.usertrax.io/api/events;proxy_ssl_server_name on;proxy_set_header Host api.usertrax.io;proxy_set_header Content-Type $http_content_type;proxy_set_header Accept $http_accept;proxy_set_header User-Agent $http_user_agent;proxy_set_header X-Auth-Key $http_x_auth_key;}Update your HTML
<script>window.usertraxConfig = {endpoint: "/api/usertrax/events",};</script><script src="/cvs.js" data-key="YOUR_API_KEY" defer></script>Test and reload Nginx
Terminal-Fenster sudo nginx -tsudo nginx -s reload
Full server block example
Section titled “Full server block example”server { listen 443 ssl http2; server_name yourdomain.com;
# ... SSL and root config ...
location = /cvs.js { proxy_pass https://usertrax.io/cvs.js; proxy_ssl_server_name on; proxy_set_header Host usertrax.io; add_header Cache-Control "public, max-age=86400"; }
location = /api/usertrax/events { proxy_pass https://api.usertrax.io/api/events; proxy_ssl_server_name on; proxy_set_header Host api.usertrax.io; proxy_set_header Content-Type $http_content_type; proxy_set_header Accept $http_accept; proxy_set_header User-Agent $http_user_agent; proxy_set_header X-Auth-Key $http_x_auth_key; }
location / { try_files $uri $uri/ /index.html; }}Verification
Section titled “Verification”- Visit your website
- Open the Network tab
- Confirm
cvs.jsand event POSTs use your domain
Troubleshooting
Section titled “Troubleshooting”- 502 Bad Gateway: Check that Nginx can reach
usertrax.ioandapi.usertrax.io(DNS, firewall) - 401 Unauthorized: Verify
X-Auth-Keyis forwarded — some Nginx configs strip unknown headers by default