pid /var/log/nginx/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; # 로그 설정 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log warn; sendfile on; keepalive_timeout 65; # user 1000:1000 실행 시 /var/cache/nginx 접근 불가 → logs 경로로 우회 client_body_temp_path /var/log/nginx/client_temp; proxy_temp_path /var/log/nginx/proxy_temp; fastcgi_temp_path /var/log/nginx/fastcgi_temp; uwsgi_temp_path /var/log/nginx/uwsgi_temp; scgi_temp_path /var/log/nginx/scgi_temp; # 업로드 파일 크기 / 타임아웃 (10GB, 10분) client_max_body_size 10G; client_body_timeout 600s; # Docker 내부 DNS - 시작 시 upstream 조회 실패 방지 resolver 127.0.0.11 valid=30s ipv6=off; # HTTP → HTTPS 리다이렉트 서버 server { listen 80; server_name api.train-kamco.com train-kamco.com; # 모든 HTTP 요청을 HTTPS로 리다이렉트 return 301 https://$host$request_uri; } # HTTPS 서버 설정 server { listen 443 ssl; http2 on; server_name api.train-kamco.com; ssl_certificate /etc/nginx/ssl/train-kamco.com.crt; ssl_certificate_key /etc/nginx/ssl/train-kamco.com.key; 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:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; ssl_prefer_server_ciphers off; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; # CORS 헤더 add_header Access-Control-Allow-Origin "https://train-kamco.com" always; add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, PATCH, OPTIONS" always; add_header Access-Control-Allow-Headers "Authorization, Content-Type, Cookie, X-Requested-With" always; add_header Access-Control-Allow-Credentials "true" always; location / { if ($request_method = OPTIONS) { return 204; } set $api http://kamco-train-api:8080; proxy_pass $api; 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_set_header X-Forwarded-Host $server_name; proxy_pass_request_headers on; proxy_set_header Cookie $http_cookie; proxy_set_header Authorization $http_authorization; proxy_connect_timeout 600s; proxy_send_timeout 600s; proxy_read_timeout 600s; proxy_request_buffering off; proxy_buffering off; } location /monitor/health { set $api http://kamco-train-api:8080; proxy_pass $api/monitor/health; access_log off; } } # HTTPS 서버 설정 - Next.js Web Application server { listen 443 ssl; http2 on; server_name train-kamco.com; ssl_certificate /etc/nginx/ssl/train-kamco.com.crt; ssl_certificate_key /etc/nginx/ssl/train-kamco.com.key; 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:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384'; ssl_prefer_server_ciphers off; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header X-XSS-Protection "1; mode=block" always; location /api/ { set $api http://kamco-train-api:8080; proxy_pass $api/api/; 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_set_header X-Forwarded-Host $server_name; proxy_pass_request_headers on; proxy_set_header Cookie $http_cookie; proxy_connect_timeout 600s; proxy_send_timeout 600s; proxy_read_timeout 600s; proxy_request_buffering off; proxy_buffering off; } location / { set $web http://kamco-train-web:3002; proxy_pass $web; 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_set_header X-Forwarded-Host $server_name; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_connect_timeout 600s; proxy_send_timeout 600s; proxy_read_timeout 600s; proxy_buffering on; proxy_buffer_size 4k; proxy_buffers 8 4k; proxy_busy_buffers_size 8k; } } }