2026-07-17 15:16:13 +08:00
|
|
|
|
|
|
|
|
# Setup this path to coconut-leaf frontend.
|
|
|
|
|
set $frontend_root /var/www/coconut-leaf/frontend/dist;
|
|
|
|
|
|
2026-05-12 15:32:30 +08:00
|
|
|
# ============================
|
2026-07-17 15:16:13 +08:00
|
|
|
# Route 1: /web -> Vite-built SPA
|
2026-05-12 15:32:30 +08:00
|
|
|
# ============================
|
|
|
|
|
location /web {
|
2026-07-17 15:16:13 +08:00
|
|
|
alias $frontend_root;
|
|
|
|
|
index index.html;
|
|
|
|
|
|
|
|
|
|
# Optimize for static file
|
2026-05-12 15:32:30 +08:00
|
|
|
expires 7d;
|
|
|
|
|
add_header Cache-Control "public, max-age=604800";
|
|
|
|
|
gzip_static on;
|
2026-07-17 15:16:13 +08:00
|
|
|
|
|
|
|
|
# SPA fallback: for non-file routes, serve index.html
|
|
|
|
|
try_files $uri $uri/ /web/index.html;
|
2026-05-12 15:32:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ============================
|
2026-07-17 15:16:13 +08:00
|
|
|
# Route 3: /api -> reverse proxy to backend
|
2026-05-12 15:32:30 +08:00
|
|
|
# ============================
|
|
|
|
|
location /api {
|
2026-07-17 15:16:13 +08:00
|
|
|
# Rewrite to remove "api" prefix
|
|
|
|
|
rewrite ^/api(/.*)$ $1 break;
|
|
|
|
|
|
|
|
|
|
# Reverse proxy to localhost backend
|
2026-05-12 15:32:30 +08:00
|
|
|
proxy_pass http://127.0.0.1:8848;
|
2026-07-17 15:16:13 +08:00
|
|
|
|
|
|
|
|
# Keep original request headers
|
2026-05-12 15:32:30 +08:00
|
|
|
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;
|
2026-07-17 15:16:13 +08:00
|
|
|
|
|
|
|
|
# Optional: WebSocket support
|
2026-05-12 15:32:30 +08:00
|
|
|
# proxy_http_version 1.1;
|
|
|
|
|
# proxy_set_header Upgrade $http_upgrade;
|
|
|
|
|
# proxy_set_header Connection "upgrade";
|
|
|
|
|
|
2026-07-17 15:16:13 +08:00
|
|
|
# Time configuration
|
2026-05-12 15:32:30 +08:00
|
|
|
proxy_connect_timeout 60s;
|
|
|
|
|
proxy_send_timeout 60s;
|
|
|
|
|
proxy_read_timeout 60s;
|
2026-07-17 15:16:13 +08:00
|
|
|
|
|
|
|
|
# Buffer setup (changed when meeting large file uploading)
|
2026-05-12 15:32:30 +08:00
|
|
|
proxy_buffering on;
|
|
|
|
|
proxy_buffer_size 4k;
|
|
|
|
|
proxy_buffers 8 4k;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# ============================
|
2026-07-17 15:16:13 +08:00
|
|
|
# Root path redirect: Root -> /web/home
|
2026-05-12 15:32:30 +08:00
|
|
|
# ============================
|
|
|
|
|
location = / {
|
2026-07-17 15:16:13 +08:00
|
|
|
return 302 /web/home;
|
2026-05-12 15:32:30 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-17 15:16:13 +08:00
|
|
|
# Deny hidden files at root level
|
2026-05-12 15:32:30 +08:00
|
|
|
location ~ /\. {
|
|
|
|
|
deny all;
|
|
|
|
|
return 404;
|
2026-07-17 15:16:13 +08:00
|
|
|
}
|