# Plaza 独立入口（plaza.tkmind.cn）
# 安装：/etc/nginx/conf.d/plaza.tkmind.cn.conf
#
#   /plaza、/_next  → goose-plaza-web :3002
#   /api、/auth、/u  → goose-h5 :8080（Plaza API + 登录 + 发布页嵌入）

upstream goose_plaza_web {
    server 127.0.0.1:3002;
    keepalive 16;
}

upstream goose_plaza_api {
    server 127.0.0.1:8080;
    keepalive 16;
}

server {
    listen 80;
    listen [::]:80;
    server_name plaza.tkmind.cn;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

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

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name plaza.tkmind.cn;

    ssl_certificate /etc/letsencrypt/live/plaza.tkmind.cn/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/plaza.tkmind.cn/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location ^~ /api/ {
        proxy_pass http://goose_plaza_api;
        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 120;
        proxy_buffering off;
    }

    location ^~ /auth/ {
        proxy_pass http://goose_plaza_api;
        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_buffering off;
    }

    location ^~ /u/ {
        proxy_pass http://goose_plaza_api;
        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 120;
        proxy_buffering off;
    }

    location / {
        proxy_pass http://goose_plaza_web;
        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_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_read_timeout 120;
        proxy_buffering off;
    }
}
