141 lines
4.3 KiB
Plaintext
141 lines
4.3 KiB
Plaintext
# CaStAD Nginx Configuration
|
|
# Target: castad1.ktenterprise.net
|
|
#
|
|
# 설치 방법:
|
|
# sudo cp nginx.castad.conf /etc/nginx/sites-available/castad
|
|
# sudo ln -s /etc/nginx/sites-available/castad /etc/nginx/sites-enabled/
|
|
# sudo nginx -t && sudo systemctl reload nginx
|
|
#
|
|
|
|
upstream castad_backend {
|
|
server 127.0.0.1:3001;
|
|
keepalive 64;
|
|
}
|
|
|
|
upstream castad_instagram {
|
|
server 127.0.0.1:5001;
|
|
keepalive 32;
|
|
}
|
|
|
|
# HTTP → HTTPS 리다이렉트
|
|
server {
|
|
listen 80;
|
|
server_name castad1.ktenterprise.net;
|
|
return 301 https://$server_name$request_uri;
|
|
}
|
|
|
|
# HTTPS 메인 서버
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name castad1.ktenterprise.net;
|
|
|
|
# SSL 인증서 (Let's Encrypt 사용 시)
|
|
ssl_certificate /etc/letsencrypt/live/castad1.ktenterprise.net/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/castad1.ktenterprise.net/privkey.pem;
|
|
|
|
# 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;
|
|
|
|
# 보안 헤더
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
# 클라이언트 요청 크기 (이미지 업로드용)
|
|
client_max_body_size 100M;
|
|
client_body_timeout 300s;
|
|
|
|
# Gzip 압축
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
|
|
|
|
# 로그
|
|
access_log /var/log/nginx/castad_access.log;
|
|
error_log /var/log/nginx/castad_error.log;
|
|
|
|
# 정적 파일 (빌드된 프론트엔드)
|
|
root /home/castad/castad/dist;
|
|
index index.html;
|
|
|
|
# API 프록시 (백엔드)
|
|
location /api/ {
|
|
proxy_pass http://castad_backend;
|
|
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;
|
|
}
|
|
|
|
# 렌더링 엔드포인트 (긴 타임아웃)
|
|
location /render/ {
|
|
proxy_pass http://castad_backend;
|
|
proxy_http_version 1.1;
|
|
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_read_timeout 600s; # 10분 (영상 렌더링용)
|
|
proxy_connect_timeout 75s;
|
|
proxy_buffering off;
|
|
}
|
|
|
|
# 다운로드 파일
|
|
location /downloads/ {
|
|
proxy_pass http://castad_backend;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
}
|
|
|
|
# 임시 파일 (렌더링 미리보기)
|
|
location /temp/ {
|
|
proxy_pass http://castad_backend;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
}
|
|
|
|
# Instagram API (Python 서비스)
|
|
location /instagram/ {
|
|
proxy_pass http://castad_instagram/;
|
|
proxy_http_version 1.1;
|
|
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_read_timeout 120s;
|
|
}
|
|
|
|
# SPA 라우팅 (React Router)
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
|
|
# 정적 에셋 캐싱
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
}
|
|
|
|
# 헬스체크
|
|
location /health {
|
|
proxy_pass http://castad_backend/api/health;
|
|
proxy_http_version 1.1;
|
|
access_log off;
|
|
}
|
|
}
|