fix: Nginx resolver for Docker DNS — prevent stale upstream IPs
Use Docker embedded DNS (127.0.0.11) with 30s TTL and variable-based proxy_pass so nginx re-resolves the API container IP after recreates instead of caching the startup IP forever. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
c6f69019cf
commit
08d7d19d0e
1 changed files with 9 additions and 3 deletions
|
|
@ -4,14 +4,19 @@ server {
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
index index.html;
|
index index.html;
|
||||||
|
|
||||||
|
# Use Docker's embedded DNS with 30s TTL so upstream IPs refresh
|
||||||
|
# after container recreates
|
||||||
|
resolver 127.0.0.11 valid=30s ipv6=off;
|
||||||
|
|
||||||
# SPA fallback
|
# SPA fallback
|
||||||
location / {
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
# API proxy
|
# API proxy — variable forces nginx to re-resolve on each request
|
||||||
location /api/ {
|
location /api/ {
|
||||||
proxy_pass http://chrysopedia-api:8000;
|
set $backend http://chrysopedia-api:8000;
|
||||||
|
proxy_pass $backend;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
|
|
@ -19,6 +24,7 @@ server {
|
||||||
}
|
}
|
||||||
|
|
||||||
location /health {
|
location /health {
|
||||||
proxy_pass http://chrysopedia-api:8000;
|
set $backend http://chrysopedia-api:8000;
|
||||||
|
proxy_pass $backend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue