Files
ERP/frontend/nginx.conf
T
ali_mohaghegh b4ed18af71 fix(nginx): resolve api upstream at request time via Docker DNS
After the api container restarts it gets a new IP; nginx cached the old one
at startup and kept proxying /api/* to the stale address — which by then
belonged to another service (casdoor), so login returned Casdoor's error
envelope and the frontend crashed with "Cannot read properties of null
(reading 'user')". proxy_pass now uses a variable + resolver 127.0.0.11 so
the upstream re-resolves per request. Verified: login works, and still works
after restarting the api container.
2026-09-02 18:42:02 +03:30

43 lines
1.5 KiB
Nginx Configuration File

# Frontend nginx config
# - Serves the built SPA from /usr/share/nginx/html
# - Proxies /api/* to the backend service (Docker compose network name: api)
server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# حداکثر حجم فایل‌های آپلودی (فاکتور/پیش‌فاکتور) — پیش‌فرض nginx فقط ۱ مگابایت
# است و آپلودهای بزرگ‌تر با خطای 413 رد می‌شوند.
client_max_body_size 50m;
# API reverse proxy -> FastAPI backend (port 8000)
# NOTE: upstream is resolved at REQUEST time through Docker's embedded DNS
# (127.0.0.11). A plain `proxy_pass http://api:8000` caches the container
# IP at nginx startup, so after the api container restarts and gets a new
# IP, nginx keeps proxying to the stale address (which may belong to
# another service) until this container is restarted too.
location /api/ {
resolver 127.0.0.11 valid=10s ipv6=off;
set $api_upstream http://api:8000;
proxy_pass $api_upstream;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# SPA fallback — all client-side routes go to index.html
location / {
try_files $uri $uri/ /index.html;
}
# Static assets cache
location /assets/ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}