Files

63 lines
2.2 KiB
Nginx Configuration File

server {
listen 80;
server_name _;
root /usr/share/nginx/html;
index index.html;
# 폴더 주소로 넘길 때 포트가 빠지지 않게 상대 주소로 보낸다
absolute_redirect off;
# 앞단 프록시(사설망)가 붙인 X-Forwarded-For 에서 실제 접속 주소를 꺼내 $remote_addr 로 쓴다 (비로그인 좋아요를 IP 로 세려고)
set_real_ip_from 172.16.0.0/12;
set_real_ip_from 10.0.0.0/8;
set_real_ip_from 192.168.0.0/16;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
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;
}
# 지역 검색 페이지: 백엔드가 정적 HTML(today·tomorrow/…/….html)에 오늘·내일 날씨를 채워 준다. 백엔드가 안 되면 정적 HTML 그대로
location ~ ^/(today|tomorrow)/[a-z]+/[a-z]+(/[a-z]+)?$ {
resolver 127.0.0.11 valid=10s ipv6=off;
set $api http://backend:9800;
proxy_pass $api/v1/seo$uri;
proxy_set_header Host $host;
proxy_connect_timeout 3s;
proxy_read_timeout 20s;
proxy_intercept_errors on;
error_page 404 500 502 503 504 = @static;
}
location @static {
add_header Cache-Control "no-cache";
try_files $uri.html /index.html;
}
# SPA: /gak 처럼 빌드 때 만든 페이지별 HTML(gak.html)이 있으면 그것을, 없으면 index.html. 폴더는 안 찾는다 (/season 이 이미지 폴더 public/season 과 겹쳐 403)
location / {
add_header Cache-Control "no-cache";
try_files $uri $uri.html /index.html;
}
}