# ═══════════════════════════════════════
# API: sub2api 中转站
# ═══════════════════════════════════════
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 /api/ {
        rewrite ^/api/v1/(.*) /v1/$1 break;
        rewrite ^/api/(.*) /v1/$1 break;
        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;
    }

    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
# ═══════════════════════════════════════
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;

    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
# ═══════════════════════════════════════
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;

    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;
    }
}

# ═══════════════════════════════════════
# Resume: 简历编辑器

# ═══════════════════════════════════════
# Main: 裸域 & www 重定向到 Resume
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name wanyue.online www.wanyue.online;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name wanyue.online www.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;

    return 301 https://resume.wanyue.online$request_uri;
}
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name resume.wanyue.online;

    location ^~ /.well-known/acme-challenge/ {
        root /var/www/html;
    }
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name resume.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/resume-pro/packages/web/dist;
    index index.html;

    location /api/ {
        proxy_pass http://127.0.0.1:4200;
        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://127.0.0.1:4200;
        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 /health {
        proxy_pass http://127.0.0.1:4200;
        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 / {
        try_files $uri $uri/ /index.html;
    }
}

# ═══════════════════════════════════════
# Study: CS Interview Knowledge Map
# ═══════════════════════════════════════
server {
    listen 80;
    listen [::]:80;
    server_name study.wanyue.online;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name study.wanyue.online;
    ssl_certificate /etc/letsencrypt/live/study.wanyue.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/study.wanyue.online/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    root /local/usr/cs-interview-dist2;
    index index.html;

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