# ═══════════════════════════════════════════════════════════
# 国内域名 · ICP备案落地页 Nginx 配置 (阿里云临时服务器)
# ═══════════════════════════════════════════════════════════
#
# 编号: ALI-NGX-CN-LANDING
# 服务器: ALI-SVR · 8.155.62.235 · 阿里云
# 守护: 铸渊 · ICE-GL-ZY001
# 版权: 国作登字-2026-A-00037559
#
# 架构:
#   guanghulab.com / www.guanghulab.com → 国内用户首页
#   前端: /opt/guanghulab-landing/sites/cn-landing/ (静态HTML)
#   用途: ICP备案合规展示 · 域名备案迁移期间临时使用
#
# ⚠️ 注意:
#   - 此文件是唯一的Nginx站点配置，default_server确保优先级
#   - 所有文件隔离在 /opt/guanghulab-landing/ 目录下
#   - 部署workflow会自动禁用所有冲突配置（包括旧站点、certbot残留）
#   - SSL配置由部署workflow根据证书存在情况自动注入
#
# 域名变量由部署工作流注入:
#   ALI_CN_DOMAIN_PLACEHOLDER → guanghulab.com
#
# SSL占位符由部署工作流根据证书状态注入:
#   __SSL_BLOCK_PLACEHOLDER__ → SSL listen + 证书配置（有证书时）
#   __HTTP_REDIRECT_BLOCK_PLACEHOLDER__ → HTTP→HTTPS重定向server块（有证书时）
# ═══════════════════════════════════════════════════════════

__HTTP_REDIRECT_BLOCK_PLACEHOLDER__

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    __SSL_BLOCK_PLACEHOLDER__
    server_name ALI_CN_DOMAIN_PLACEHOLDER www.ALI_CN_DOMAIN_PLACEHOLDER;

    # ─── 安全头 ───
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header X-Server-Identity "ALI-SVR-CN-LANDING" always;
    add_header X-Site-Mode "cn-landing-ali" always;

    # ─── 静态文件根目录 · 国内落地页 ───
    root /opt/guanghulab-landing/sites/cn-landing;
    index index.html;

    # ─── 前端静态文件 ───
    location / {
        try_files $uri $uri/ /index.html;
    }

    # ─── 健康探针 ───
    location = /health {
        access_log off;
        return 200 '{"status":"ok","server":"ali-cn","role":"cn-landing","domain":"ALI_CN_DOMAIN_PLACEHOLDER"}';
        add_header Content-Type application/json;
    }

    # ─── 静态资源缓存 ───
    location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
        expires 7d;
        add_header Cache-Control "public, immutable";
    }

    # ─── 错误页面 ───
    error_page 404 /index.html;
    error_page 500 502 503 504 /index.html;

    # ─── 访问日志 (隔离目录) ───
    access_log /opt/guanghulab-landing/logs/nginx-access.log;
    error_log /opt/guanghulab-landing/logs/nginx-error.log;
}
