## 응용 예제 ③ — TLS termination + HTTP→HTTPS 리다이렉트
## 자가서명 인증서를 /etc/nginx/certs/ 에 미리 생성 (setup_04_tls.sh 참조)

# 80 → 443 강제 리다이렉트
server {
    listen 80;
    server_name api.lab.local;
    return 301 https://$host$request_uri;
}

# 443 TLS termination → 백엔드 평문
server {
    listen 443 ssl http2;
    server_name api.lab.local;

    ssl_certificate     /etc/nginx/certs/api.lab.local.crt;
    ssl_certificate_key /etc/nginx/certs/api.lab.local.key;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    ssl_session_cache   shared:SSL:10m;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    access_log /var/log/nginx/lab-tls.access.log;
}
