From ae546db19f4f1ed2f82ecadd07960cc2ba1d59a8 Mon Sep 17 00:00:00 2001 From: tisachi Date: Tue, 27 Oct 2026 06:25:11 +0100 Subject: [PATCH] Ops+App+Admin: dynamiczne rozwiazywanie upstreamu API w nginx frontow (resolver 127.0.0.11 + zmienna w proxy_pass) i depends_on zdrowego api dla app/admin w compose deploy (usuwa 502 na /api po recreacji kontenera api) --- admin/nginx.conf.template | 9 +++++++-- app/nginx.conf.template | 9 +++++++-- ops/deploy/compose.yml | 7 +++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/admin/nginx.conf.template b/admin/nginx.conf.template index e33f81a..641462e 100644 --- a/admin/nginx.conf.template +++ b/admin/nginx.conf.template @@ -9,6 +9,11 @@ server { root /usr/share/nginx/html; index index.html; + # DNS Dockera (127.0.0.11) + zmienna w proxy_pass: upstream rozwiazywany + # dynamicznie — po recreacji kontenera api nginx nie trzyma starego IP (502) + resolver 127.0.0.11 valid=10s ipv6=off; + set $api_upstream ${API_UPSTREAM}; + location ~ ^/(index\.html|config\.js|manifest\.json)$ { add_header Cache-Control "no-cache"; try_files $uri /index.html; @@ -20,7 +25,7 @@ server { location /api/ { # upload zdjec do 5 MB + zapas client_max_body_size 10m; - proxy_pass http://${API_UPSTREAM}; + proxy_pass http://$api_upstream; # $http_host (nie $host!) — zachowuje port: Express porownuje Origin z Host # i inaczej requesty na srodowisku z jawnych portem (staging 13xxx, dev 9xxx) # wygladalyby na cross-origin @@ -31,7 +36,7 @@ server { } location = /health { - proxy_pass http://${API_UPSTREAM}; + proxy_pass http://$api_upstream; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; diff --git a/app/nginx.conf.template b/app/nginx.conf.template index aebdc0f..9360f4e 100644 --- a/app/nginx.conf.template +++ b/app/nginx.conf.template @@ -9,6 +9,11 @@ server { root /usr/share/nginx/html; index index.html; + # DNS Dockera (127.0.0.11) + zmienna w proxy_pass: upstream rozwiazywany + # dynamicznie — po recreacji kontenera api nginx nie trzyma starego IP (502) + resolver 127.0.0.11 valid=10s ipv6=off; + set $api_upstream ${API_UPSTREAM}; + # dev: zero cache'owania JS/CSS/HTML — aktualizacje widoczne od razu po rebuildzie # (Vite generuje hashowane nazwy assetów, więc long-term cache byłby bezpieczne, # ale utrudnia weryfikację zmian na telefonie) @@ -26,7 +31,7 @@ server { location /api/ { # upload zdjec do 5 MB + zapas client_max_body_size 10m; - proxy_pass http://${API_UPSTREAM}; + proxy_pass http://$api_upstream; # $http_host (nie $host!) — zachowuje port: Express porownuje Origin z Host # i inaczej requesty na srodowisku z jawnych portem (staging 13xxx, dev 9xxx) # wygladalyby na cross-origin @@ -37,7 +42,7 @@ server { } location = /health { - proxy_pass http://${API_UPSTREAM}; + proxy_pass http://$api_upstream; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; diff --git a/ops/deploy/compose.yml b/ops/deploy/compose.yml index 62f481d..1f3f967 100644 --- a/ops/deploy/compose.yml +++ b/ops/deploy/compose.yml @@ -71,6 +71,10 @@ services: - "${APP_HOST_PORT:?set APP_HOST_PORT in .env}:9001" environment: API_UPSTREAM: api:9002 + # nginx startuje po zdrowym api — wlasciwe DNS i kolejnosc przy recreacji + depends_on: + api: + condition: service_healthy restart: unless-stopped admin: @@ -80,6 +84,9 @@ services: - "${ADMIN_HOST_PORT:?set ADMIN_HOST_PORT in .env}:9000" environment: API_UPSTREAM: api:9002 + depends_on: + api: + condition: service_healthy restart: unless-stopped # Strona-wizytówka (nginx, zero API) — porty CTA w config.js generowane