nginx resolves proxy_pass hostnames at startup, before the api container is reachable. Using resolver 127.0.0.11 + set $api defers resolution to request time. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
22 lines
646 B
Nginx Configuration File
22 lines
646 B
Nginx Configuration File
server {
|
|
listen 80;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# SPA routing — return index.html for all non-file routes
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# Proxy API calls to the backend container
|
|
# Use Docker's internal DNS resolver so upstream resolves at request time
|
|
resolver 127.0.0.11 valid=10s;
|
|
set $api http://api:3001;
|
|
location /api/ {
|
|
proxy_pass $api/;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
}
|
|
}
|