Skip to Content
Zerobyte

Reverse Proxy

Run Zerobyte behind Nginx, Caddy, or Traefik with HTTPS

When running Zerobyte behind a reverse proxy, you need to configure the BASE_URL environment variable with your HTTPS domain and ensure your proxy passes the correct headers.

Prerequisites

Set the following environment variables in your compose.yaml:

environment:
  - BASE_URL=https://zerobyte.example.com
  - TRUST_PROXY=true

TRUST_PROXY=true lets authentication use the public host and protocol from X-Forwarded-Host and X-Forwarded-Proto. Set it when your HTTPS proxy forwards requests to Zerobyte over HTTP. Only enable it when the proxy controls those headers and clients cannot reach Zerobyte directly.

Restart the container after making changes:

docker compose down && docker compose up -d

Zerobyte uses BASE_URL to determine whether authentication cookies should be marked as Secure. This directly affects how login sessions work:

BASE_URL valueCookie behavior
http:// or IP address (e.g., http://192.168.1.100:4096)Secure cookies disabled, cookies sent over HTTP. Suitable for local network access.
https:// with domain (e.g., https://zerobyte.example.com)Secure cookies enabled, cookies only sent over HTTPS. Required for production.

If BASE_URL is set to an https:// address, browsers will only send authentication cookies over HTTPS connections. Accessing Zerobyte over plain HTTP will fail with login loops or session errors. Make sure your reverse proxy terminates TLS before forwarding to Zerobyte.

Proxy configurations

Nginx

Create a server block for Zerobyte. This configuration handles TLS termination and forwards requests to the container:

server {
    listen 443 ssl http2;
    server_name zerobyte.example.com;

    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;

    location / {
        proxy_pass http://localhost:4096;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Reload Nginx after saving:

sudo nginx -t && sudo systemctl reload nginx

Binding to localhost

If you are using a reverse proxy on the same machine, bind the Zerobyte port to 127.0.0.1 so it is not directly accessible from the network:

ports:
  - "127.0.0.1:4096:4096"

This ensures all traffic goes through your reverse proxy, which handles TLS and authentication headers.

Security considerations

Exposing Zerobyte to the internet requires care. Even behind a reverse proxy with HTTPS, make sure you:

  • Bind the container port to localhost only (127.0.0.1:4096:4096) so it cannot be accessed directly.
  • Use a strong APP_SECRET (generated with openssl rand -hex 32).
  • Keep Zerobyte updated to the latest version.
  • Consider placing Zerobyte behind a secure tunnel (Cloudflare Tunnel, Tailscale, WireGuard) for an additional layer of protection.

A note on TRUSTED_ORIGINS

BASE_URL is trusted automatically. If you access Zerobyte through other addresses, add their complete origins to TRUSTED_ORIGINS, including the scheme and any non-default port. Only list origins you control and trust.

Prefer explicit origins. If using CSRF wildcards, include the scheme, such as https://*.example.com; scheme-less wildcards trust both HTTP and HTTPS. CORS requires exact origins, and cross-origin scripts cannot read cookie-authenticated responses.

Your proxy must preserve the browser's Origin and Sec-Fetch-Site headers. HTTPS termination with an HTTP upstream is supported.

TRUSTED_ORIGINS does not change cookie security. When BASE_URL uses HTTPS, cookie-authenticated access still requires HTTPS.

# Additional trusted public origin; secure cookies still require HTTPS
environment:
  - BASE_URL=https://zerobyte.example.com
  - TRUSTED_ORIGINS=https://other-app.example.com

Verifying your setup

After configuring your reverse proxy:

Test HTTPS access

Open https://zerobyte.example.com in your browser. You should see the Zerobyte login page with a valid TLS certificate.

Check headers

Verify that your proxy is forwarding the correct headers. In the Zerobyte container logs, you should see requests coming from your proxy:

docker compose logs -f zerobyte

Confirm login works

Log in with your admin credentials. If login fails or loops, double-check that BASE_URL matches the URL you are accessing and that cookies are being set correctly over HTTPS.