From 7271dadbee9720f32b628883bcb6ac62097b6db0 Mon Sep 17 00:00:00 2001 From: Daniel Santillan Date: Wed, 23 Sep 2026 11:01:01 -0400 Subject: [PATCH] The deploy path's nginx: re-resolve the api on every request MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A plain `proxy_pass http://api:3000` is resolved once, when nginx starts, and the address stays pinned for the life of the container. Recreate the api — a deploy that changes its configuration, a --force-recreate, any restart that hands it a new IP — and the web container keeps talking to a dead address: every /api call answers 502, including /api/config, so the app cannot even boot. That is not hypothetical: it is what happened on gym.dploy.lol, where restarting the api to pick up new code produced 502 on every endpoint until the web container was restarted too. The generated config now asks Docker's embedded DNS again on every request instead: `resolver 127.0.0.11` plus `set $api_upstream http://api:3000` and `proxy_pass $api_upstream`. This is the same fix web/nginx.conf.template has carried for the registry-image shape (with a comment explaining issue #16), and comment 4 at the top of this file now records why the deploy path needs it too. Verified by rendering the command exactly as the container runs it and passing the result through an nginx config parser: both body limits in place, both locations on the variable, and the upstream still resolved through the embedded resolver. --- deploy/compose-build-at-deploy.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/deploy/compose-build-at-deploy.yml b/deploy/compose-build-at-deploy.yml index 5cdba13..0855ee2 100644 --- a/deploy/compose-build-at-deploy.yml +++ b/deploy/compose-build-at-deploy.yml @@ -36,6 +36,14 @@ # the registry-image path (docker-compose.yml) and is NOT read here. A change to the limits # has to be made in both, or the two deployment shapes diverge. # +# 4. nginx resolves `api` through a VARIABLE, not by name. A plain `proxy_pass http://api:3000` +# is resolved once, when nginx starts, and the address is then pinned for the life of the +# container: recreate the api — a deploy that changes its configuration, a `--force-recreate`, +# a manual restart that gives it a new IP — and every /api call answers 502 until the web +# container is restarted too, including /api/config, so the app cannot even load. The +# `resolver` + `set $api_upstream` pair below makes nginx ask again on every request, which is +# the same fix web/nginx.conf.template carries (and explains at length) for the other shape. +# # To deploy a change to the code, force the one-shot services to run again — `source` and # `web-build` have `restart: "no"`, so compose leaves them alone when their configuration has not # changed: @@ -192,7 +200,7 @@ services: command: - /bin/sh - -c - - "printf 'server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; client_max_body_size 5m; location /api/vitals/ingest { client_max_body_size 32m; proxy_pass http://api:3000; proxy_http_version 1.1; proxy_set_header 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; } location /api/ { proxy_pass http://api:3000; proxy_http_version 1.1; proxy_set_header 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; } location / { try_files $$uri $$uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'" + - "printf 'server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; client_max_body_size 5m; resolver 127.0.0.11 valid=10s ipv6=off; set $$api_upstream http://api:3000; location /api/vitals/ingest { client_max_body_size 32m; proxy_pass $$api_upstream; proxy_http_version 1.1; proxy_set_header 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; } location /api/ { proxy_pass $$api_upstream; proxy_http_version 1.1; proxy_set_header 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; } location / { try_files $$uri $$uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'" restart: unless-stopped volumes: