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.
This commit is contained in:
+8
-1
@@ -14,8 +14,15 @@ server {
|
||||
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/ {
|
||||
proxy_pass http://api:8000;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user