# 80 → 301 → 443
server {
    listen 80;
    listen [::]:80;
    server_name app-api.shaguabijia.com;
    return 301 https://$host$request_uri;
}

# 443 SSL 反代到本地 uvicorn (127.0.0.1:8770)
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name app-api.shaguabijia.com;

    ssl_certificate     /etc/nginx/ssl/app-api.shaguabijia.com.pem;
    ssl_certificate_key /etc/nginx/ssl/app-api.shaguabijia.com.key;

    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    ssl_session_cache   shared:SSL:10m;

    client_max_body_size 4m;

    location / {
        proxy_pass http://127.0.0.1:8770;
        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 30s;
    }
}
