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)

This commit is contained in:
tisachi
2026-10-27 06:25:11 +01:00
parent a230dee285
commit ae546db19f
3 changed files with 21 additions and 4 deletions

View File

@@ -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;

View File

@@ -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;

View File

@@ -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