# 美家卡智影 API - Nginx 反向代理配置 (acme.sh)
# ===========================================
# 域名: dev.tapi.meijiaka.cn (测试环境)
#
# 证书由 acme.sh 自动管理，路径:
#   /etc/nginx/ssl/dev.tapi.meijiaka.cn.key
#   /etc/nginx/ssl/dev.tapi.meijiaka.cn.crt

server {
    listen 80;
    server_name dev.tapi.meijiaka.cn;

    # acme.sh 验证路径
    location /.well-known/acme-challenge/ {
        root /var/www/acme-challenge;
    }

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

server {
    listen 443 ssl http2;
    server_name dev.tapi.meijiaka.cn;

    # SSL 证书（由 acme.sh install-cert 部署）
    ssl_certificate /etc/nginx/ssl/dev.tapi.meijiaka.cn.crt;
    ssl_certificate_key /etc/nginx/ssl/dev.tapi.meijiaka.cn.key;

    # SSL 安全配置
    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;
    ssl_prefer_server_ciphers off;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;

    # 日志
    access_log /var/log/nginx/meijiaka-zy.access.log;
    error_log /var/log/nginx/meijiaka-zy.error.log;

    # 反向代理到 Docker 容器（8081 端口）
    location / {
        proxy_pass http://127.0.0.1:8081;
        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_connect_timeout 60s;
        proxy_send_timeout 120s;
        proxy_read_timeout 120s;

        client_max_body_size 500M;

        # 安全响应头
        add_header X-Content-Type-Options nosniff always;
        add_header X-Frame-Options DENY always;
        add_header Referrer-Policy strict-origin-when-cross-origin always;
    }
}
