HTTPS and domains
Serve your instance over HTTPS on one hostname, or give the web app and the API a domain each.
Before using your instance outside your own network, serve it over HTTPS. One hostname is enough: the bundled proxy serves the web app and the API on the same address.
One hostname
Add proxy to COMPOSE_PROFILES in .env and set both addresses to the same hostname:
APP_URL=https://money.example.com
API_URL=https://money.example.com
COMPOSE_PROFILES=proxy
TRUST_PROXY=1
BIND_ADDRESS=127.0.0.1Then run docker compose up -d and point the hostname's DNS at the machine. The proxy is Caddy: it fetches and renews the certificate itself, sends /v1/* and /api/auth/* to the API, and everything else to the web app.
Ports 80 and 443 must be reachable from the internet, because Caddy answers the certificate challenge on 80. PROXY_HTTP_PORT and PROXY_HTTPS_PORT change the published ports.
No cookie domain is needed: the sign-in cookie belongs to that one hostname. Leave AUTH_COOKIE_DOMAIN and NEXT_PUBLIC_AUTH_COOKIE_DOMAIN empty.
BIND_ADDRESS=127.0.0.1 keeps the plain-HTTP ports (the web app, the API, and the optional storage and Mailpit) on the machine, so only the proxy is reachable from outside.
To try it locally, set APP_URL=http://localhost and API_URL=http://localhost: the proxy then serves plain HTTP on port 80.
Another reverse proxy
Any other reverse proxy works: give it one hostname and route the same two path prefixes to the API. With Caddy on the host:
money.example.com {
handle /v1/* {
reverse_proxy localhost:3001
}
handle /api/auth/* {
reverse_proxy localhost:3001
}
handle {
reverse_proxy localhost:3000
}
}Two hostnames
A hostname for each still works. Give the web app and the API their own name:
money.example.com {
reverse_proxy localhost:3000
}
api.money.example.com {
reverse_proxy localhost:3001
}Then in .env:
APP_URL=https://money.example.com
API_URL=https://api.money.example.com
AUTH_COOKIE_DOMAIN=.example.com
NEXT_PUBLIC_AUTH_COOKIE_DOMAIN=.example.com
TRUST_PROXY=1The cookie domain lets the web app read the sign-in session the API sets, because they are on different subdomains of the same domain. The bundled proxy profile serves one hostname only; leave it off.
Tell the API about the proxy
The API limits how often each visitor can try to sign in, and tells visitors apart by their IP address. Behind a proxy, every request arrives from the proxy's address, and the visitor's own address comes in the X-Forwarded-For header. TRUST_PROXY says how many proxies the API can believe:
| Setup | TRUST_PROXY |
|---|---|
| No proxy: browsers connect straight to the API port | leave it empty |
One reverse proxy (the bundled proxy profile, Caddy, nginx, Traefik, a Cloudflare Tunnel) | 1 |
| Cloudflare's proxy in front of your own reverse proxy | 2 |
You can also give the proxies' addresses instead of a count, as a comma-separated list of IP addresses or ranges (for example 172.16.0.0/12).
Leave it empty when there is no proxy: otherwise anyone can write their own X-Forwarded-For and get round the limits. Set it when there is one: otherwise everyone shares the proxy's address, and one person retrying a wrong password can lock everyone else out of signing in for a while.
Keep the ports private
When the proxy runs on the same machine, set BIND_ADDRESS=127.0.0.1 in .env and run docker compose up -d. The published ports (the web app, the API, and the optional storage and Mailpit) then listen on localhost only, so they are reachable only through the proxy. WEB_PORT, API_PORT, S3_PORT and MAILPIT_PORT change those ports on the machine (3000, 3001, 9000 and 8025 by default).