# ═══════════════════════════════════════
# 主站: Halo 博客
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name wanyue.online;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name wanyue.online;
    ssl_certificate /etc/letsencrypt/live/wanyue.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wanyue.online/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        proxy_pass http://127.0.0.1:8090;
        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 $connection_upgrade;
    }
}

# ═══════════════════════════════════════
# API: One API 中转站
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name api.wanyue.online;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name api.wanyue.online;
    ssl_certificate /etc/letsencrypt/live/wanyue.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wanyue.online/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
    client_max_body_size 50m;

    location / {
        proxy_pass http://127.0.0.1:3000;
        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;
    }
}

# ═══════════════════════════════════════
# Gist: Opengist 代码片段
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name gist.wanyue.online;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name gist.wanyue.online;
    ssl_certificate /etc/letsencrypt/live/wanyue.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wanyue.online/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        proxy_pass http://127.0.0.1:6157;
        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;
    }
}

# ═══════════════════════════════════════
# Files: File Hub 文件服务
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name files.wanyue.online;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name files.wanyue.online;
    ssl_certificate /etc/letsencrypt/live/wanyue.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wanyue.online/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        proxy_pass http://127.0.0.1:8091;
        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;
    }
}

# ═══════════════════════════════════════
# PDF: PDFCraft (built with basePath=/pdf)
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name pdf.wanyue.online;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name pdf.wanyue.online;
    ssl_certificate /etc/letsencrypt/live/wanyue.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wanyue.online/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    root /local/usr/pdfcraft/current;
    index index.html;

    # Next.js 构建时 basePath=/pdf，静态资源路径前缀需兼容
    location = /pdf { return 301 /; }
    location /pdf/ {
        rewrite ^/pdf/(.*) /$1 break;
        try_files $uri $uri/ /en/index.html;
    }

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

# ═══════════════════════════════════════
# UI: 湾悦 UI (built with base=/wanyue-ui/)
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name ui.wanyue.online;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name ui.wanyue.online;
    ssl_certificate /etc/letsencrypt/live/wanyue.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wanyue.online/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    root /local/usr/wanyue-ui/current/dist;
    index index.html;

    # VitePress 构建时 base=/wanyue-ui/，静态资源路径前缀需兼容
    location = /wanyue-ui { return 301 /; }
    location /wanyue-ui/ {
        rewrite ^/wanyue-ui/(.*) /$1 break;
        try_files $uri $uri/ /index.html;
    }

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

# ═══════════════════════════════════════
# Love: 静态页面
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name love.wanyue.online;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name love.wanyue.online;
    ssl_certificate /etc/letsencrypt/live/wanyue.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wanyue.online/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    root /local/usr/love-backup;
    index index.html;

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