fivebar

nginx

Copy page
View Markdown
Open with
Connect MCP
Claude Mistral Vibe Cursor VS Code

Two locations in your server block serve the script from your domain and pass its counts on, with the visitor’s address.

Add two locations to your site’s server block:

location = /js/tally.js {
    proxy_pass https://fiveb.ar/js/tally.js;
    proxy_set_header Host fiveb.ar;
    proxy_set_header Cookie "";
    proxy_set_header Authorization "";
    proxy_ssl_server_name on;
    proxy_ssl_verify on;
    proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
}

location = /api/tally {
    proxy_pass https://fiveb.ar/api/tally;
    proxy_set_header Host fiveb.ar;
    proxy_set_header Cookie "";
    proxy_set_header Authorization "";
    proxy_set_header X-Fivebar-IP $remote_addr;
    proxy_ssl_server_name on;
    proxy_ssl_verify on;
    proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
}

The certificates’ path varies by system: it’s /etc/pki/tls/certs/ca-bundle.crt on Red Hat and its relatives. Behind a load balancer or a CDN, $remote_addr is theirs rather than the visitor’s: set up nginx’s real IP module to read the visitor’s from them. With the GeoIP2 module, send X-Fivebar-Country and the rest from its variables too.

Load the script

Once the proxy is live, load the script from your own domain. It sends its counts to the host it was loaded from, so nothing else changes:

<script async data-domain="example.com" src="/js/tally.js"></script>

Then check it works. If either path is already taken on your site, see Other paths. Proxying says how it works and which headers name the visitor.