Nginx caches DNS at startup, so when dashboard-api restarts and gets a new container IP, the proxy breaks with 502. Use Docker's embedded DNS resolver (127.0.0.11) with a variable-based proxy_pass to re-resolve on every request. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
26 lines
633 B
Nginx Configuration File
26 lines
633 B
Nginx Configuration File
server {
|
|
listen 3000;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
# SPA — 모든 경로를 index.html로
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# API 프록시 → 백엔드 컨테이너
|
|
location /api/ {
|
|
resolver 127.0.0.11 valid=10s;
|
|
set $backend http://dashboard-api:8080;
|
|
proxy_pass $backend;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
}
|
|
|
|
# 캐시 설정
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {
|
|
expires 7d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
}
|