Files
goldenChart/frontend_golden/nginx-local.conf
T
2026-05-23 15:11:48 +09:00

163 lines
5.7 KiB
Plaintext

# 로컬 개발 환경용 nginx 설정 (localhost, 자체 서명 인증서)
# MultiChart / 실시간 차트용 Native WebSocket (Spring /ws/realtime) — 누락 시 wss 연결 실패(Code 1006)·로딩 무한 대기
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# HTTP 서버 (HTTPS로 리다이렉트 또는 직접 서비스)
server {
listen 80;
server_name localhost 127.0.0.1;
# 개발 환경에서는 HTTP로도 접근 가능 (선택사항: HTTPS로 리다이렉트)
# return 301 https://$host$request_uri;
root /usr/share/nginx/html;
index index.html;
# React Router를 위한 설정
location / {
try_files $uri $uri/ /index.html;
}
# AI Agent 프록시 (LangGraph 기반)
location /api/agent/ {
proxy_pass http://ai-agent:8000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
proxy_buffering off;
}
# API 프록시 (Spring Boot 백엔드)
location /api/ {
proxy_pass http://backend:8082/api/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
}
# WebSocket (실시간 캔들 /ws/realtime — nginx.conf 와 동일)
location /ws {
proxy_pass http://backend:8082;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
}
# HTTPS 서버 (자체 서명 인증서)
server {
listen 443 ssl http2;
server_name localhost 127.0.0.1;
# 자체 서명 SSL 인증서 설정
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
# SSL 보안 설정
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
root /usr/share/nginx/html;
index index.html;
# gzip 압축
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
gzip_min_length 1000;
# React Router를 위한 설정
location / {
try_files $uri $uri/ /index.html;
# index.html 캐시 방지 (항상 최신 버전 제공)
location = /index.html {
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
}
# AI Agent 프록시 (LangGraph 기반)
location /api/agent/ {
proxy_pass http://ai-agent:8000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
proxy_buffering off;
}
# API 프록시 (Spring Boot 백엔드)
location /api/ {
proxy_pass http://backend:8082/api/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
proxy_read_timeout 300s;
proxy_connect_timeout 75s;
# CORS는 백엔드(Spring Boot)에서 처리하므로 Nginx에서는 제거
}
# WebSocket (wss://localhost/ws/realtime → Spring RealtimeWebSocketHandler)
location /ws {
proxy_pass http://backend:8082;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
# 정적 파일 캐싱
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}