server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; # 폴더 주소로 넘길 때 포트가 빠지지 않게 상대 주소로 보낸다 absolute_redirect off; gzip on; gzip_types text/css application/javascript image/svg+xml application/json; # 해시가 붙은 빌드 파일은 오래 캐시 location /assets/ { add_header Cache-Control "public, max-age=31536000, immutable"; try_files $uri =404; } location /icons/ { add_header Cache-Control "public, max-age=604800"; try_files $uri =404; } # API 는 같은 주소로 받아 backend 컨테이너로 넘긴다 location /v1/ { # 백엔드 컨테이너가 다시 뜨면 IP 가 바뀌므로 docker DNS 로 매번 다시 찾는다 resolver 127.0.0.11 valid=10s ipv6=off; set $api http://backend:9800; proxy_pass $api; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } # SPA: /indices, /sky 같은 주소로 새로고침해도 index.html을 돌려준다. 폴더는 안 찾는다 (/season 이 이미지 폴더 public/season 과 겹쳐 403) location / { add_header Cache-Control "no-cache"; try_files $uri /index.html; } }