# 开发者子域名沙箱 · ZY-AGEOS-TOWER-2026-0326-001-S1
# 铸渊统一管理 · 人类不得手动修改
# 版权：国作登字-2026-A-00037559
#
# 前置条件（冰朔/之之配置）：
# 1. DNS: *.guanghulab.com → A → 43.134.16.246 (腾讯云·铸渊主权服务器)
# 2. SSL: certbot certonly --dns 模式获取通配符证书 *.guanghulab.com
# 注: 旧服务器 150.109.76.244 (香港) / 8.155.62.235 (阿里云) 已弃用

# HTTP → HTTPS 重定向
server {
    listen 80;
    server_name ~^(?<devid>dev-\d{3})\.guanghulab\.com$;
    return 301 https://$host$request_uri;
}

# HTTPS 子域名沙箱
server {
    listen 443 ssl;
    server_name ~^(?<devid>dev-\d{3})\.guanghulab\.com$;

    ssl_certificate /etc/letsencrypt/live/guanghulab.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/guanghulab.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;

    root /var/www/sandbox/$devid;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }

    add_header X-Sandbox-DevId $devid;

    access_log /var/log/nginx/sandbox-$devid-access.log;
    error_log /var/log/nginx/sandbox-error.log;
}
