fix(deploy): isolate web→api traffic on a private network

nginx proxied to `api:4100` over the shared `dokploy-network`, where the
generic name `api` resolved to more than one container (a stale one from a
previous deploy, or another project's service). nginx pinned those IPs at
startup and round-robined across them, so requests hit a refused upstream
and could reach a foreign container.

- api now lives only on a stack-private `internal` network, aliased as
  `superlist-api`; only web joins `dokploy-network` for Traefik.
- nginx proxies via a variable with Docker's resolver (127.0.0.11,
  valid=10s), so API redeploys never leave it on a stale IP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-10-19 12:05:20 -03:00
parent 371e59de92
commit 815dcc300d
4 changed files with 31 additions and 11 deletions

View File

@@ -9,11 +9,19 @@ server {
gzip on;
gzip_types text/css application/javascript application/json image/svg+xml;
# API proxy: no path rewrite, /api/* reaches the API as-is. `proxy_buffering
# off` and the long read timeout keep the SSE streams (/lists/:id/events)
# flowing in realtime instead of being batched or cut off.
# Docker's embedded DNS. Proxying through a variable makes nginx re-resolve
# the API on every TTL instead of pinning the IPs it saw at startup, so a
# redeployed API container (new IP) is picked up without restarting nginx.
resolver 127.0.0.11 valid=10s ipv6=off;
# API proxy: no path rewrite, /api/* reaches the API as-is (proxy_pass with a
# variable and no URI forwards the original request URI). `superlist-api` is
# the API's alias on the stack-private network (see docker-compose.yml).
# `proxy_buffering off` and the long read timeout keep the SSE streams
# (/lists/:id/events) flowing in realtime instead of being batched or cut off.
location /api/ {
proxy_pass http://api:4100;
set $api_upstream http://superlist-api:4100;
proxy_pass $api_upstream;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;