# 查价中台 — Nginx 站点配置（HTTPS）
# 安装：bash deploy/install.sh --nginx
# 或手动：
#   sudo cp deploy/nginx/chajia.conf /etc/nginx/sites-available/chajia
#   sudo ln -sf /etc/nginx/sites-available/chajia /etc/nginx/sites-enabled/chajia
#   sudo nginx -t && sudo systemctl reload nginx
#
# 将 __PUBLIC_DOMAIN__ 替换为你的域名（install.sh 会自动替换）

# HTTP → HTTPS 重定向
server {
    listen 80;
    listen [::]:80;
    server_name __PUBLIC_DOMAIN__;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name __PUBLIC_DOMAIN__;

    # 【请填写】Let's Encrypt 证书路径（certbot 签发后自动生成）
    ssl_certificate     /etc/letsencrypt/live/__PUBLIC_DOMAIN__/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/__PUBLIC_DOMAIN__/privkey.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:10m;
    ssl_protocols TLSv1.2 TLSv1.3;

    client_max_body_size 2m;

    # 地址联想 API 最长 300s，询价轮询由客户端完成
    proxy_connect_timeout 60s;
    proxy_send_timeout 320s;
    proxy_read_timeout 320s;

    location / {
        proxy_pass http://127.0.0.1:__APP_PORT__;
        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 Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_buffering off;
    }

    access_log /var/log/nginx/chajia-access.log;
    error_log  /var/log/nginx/chajia-error.log;
}
