# 查价中台 — Nginx 站点配置（HTTPS，Let's Encrypt 证书）
# 前置：已用 certbot 申请证书，例如：
#   sudo certbot certonly --nginx -d quote.example.com
# 安装：bash deploy/install.sh --nginx-ssl
# 证书路径默认：/etc/letsencrypt/live/quote.example.com/

upstream chajia_next {
    server 127.0.0.1:3000;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    # 【请修改】你的域名
    server_name quote.example.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    # 【请修改】你的域名
    server_name quote.example.com;

    # 【请修改】certbot 证书路径（与域名一致）
    ssl_certificate     /etc/letsencrypt/live/quote.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/quote.example.com/privkey.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:chajia_ssl:10m;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers off;

    client_max_body_size 2m;

    proxy_connect_timeout 60s;
    proxy_send_timeout 360s;
    proxy_read_timeout 360s;

    add_header X-Content-Type-Options nosniff always;
    add_header X-Frame-Options SAMEORIGIN always;

    location / {
        proxy_pass http://chajia_next;
        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 Connection "";
    }
}
