server {
    listen       80;
    server_name  localhost;

    client_max_body_size 50M;

    # 后端 API 代理
    location /api/ {
        proxy_pass http://${BACKEND_HOST}:8080/;
        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;
    }

    # 文件上传/下载代理
    location /uploads/ {
        proxy_pass http://${BACKEND_HOST}:8080/uploads/;
        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;
    }

    # 域名验证文件（WW_verify_xxx.txt / MP_verify_xxx.txt 等），转发到后端 static 目录
    location ~ "^/([A-Z]{2,}_verify_.*\.txt)$" {
        proxy_pass http://${BACKEND_HOST}:8080/$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;
    }

    # 前端静态资源 + SPA fallback
    location / {
        proxy_pass http://frontend:80;
        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_intercept_errors on;
        error_page 404 = /index.html;
    }
}
