99 lines
2.4 KiB
Plaintext
99 lines
2.4 KiB
Plaintext
|
|
# Setup this path to coconut-leaf legacy frontend.
|
|
set $frontend_root /var/www/coconut-leaf/frontend-legacy;
|
|
root $frontend_root;
|
|
index home.html;
|
|
|
|
# ============================
|
|
# Route 1: /web -> HTML templates with extensionless fallback
|
|
# ============================
|
|
location /web {
|
|
# Use alias to exactly mapping
|
|
alias $frontend_root/templates;
|
|
|
|
# Optimize for static file
|
|
expires 7d;
|
|
add_header Cache-Control "public, max-age=604800";
|
|
gzip_static on;
|
|
|
|
# Try file with .html suffix
|
|
try_files $uri.html $uri =404;
|
|
}
|
|
|
|
# /web/eventAdd -> templates/event.html, replace {{uuidPath}} with blank
|
|
location = /web/eventAdd {
|
|
alias $frontend_root/templates/event.html;
|
|
default_type text/html;
|
|
sub_filter '{{uuidPath}}' '';
|
|
sub_filter_once on;
|
|
}
|
|
|
|
# /web/eventUpdate/<path:uuidPath> -> templates/event.html, replace {{uuidPath}} with uuidPath
|
|
location ~ ^/web/eventUpdate/(?<uuidPath>.+)$ {
|
|
alias $frontend_root/templates/event.html;
|
|
default_type text/html;
|
|
sub_filter '{{uuidPath}}' $uuidPath;
|
|
sub_filter_once on;
|
|
}
|
|
|
|
# ============================
|
|
# Route 2: /static -> static files
|
|
# ============================
|
|
location /static {
|
|
# Use alias to exactly mapping
|
|
alias $frontend_root/static;
|
|
|
|
# Optimize for static file
|
|
expires 7d;
|
|
add_header Cache-Control "public, max-age=604800";
|
|
gzip_static on;
|
|
|
|
# Try file with .html suffix
|
|
try_files $uri $uri =404;
|
|
}
|
|
|
|
# ============================
|
|
# Route 3: /api -> reverse proxy to backend
|
|
# ============================
|
|
location /api {
|
|
# Rewrite to remove "api" prefix
|
|
rewrite ^/api(/.*)$ $1 break;
|
|
|
|
# Reverse proxy to localhost backend
|
|
proxy_pass http://127.0.0.1:8848;
|
|
|
|
# Keep original request headers
|
|
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;
|
|
|
|
# Optional: WebSocket support
|
|
# proxy_http_version 1.1;
|
|
# proxy_set_header Upgrade $http_upgrade;
|
|
# proxy_set_header Connection "upgrade";
|
|
|
|
# Time configuration
|
|
proxy_connect_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# Buffer setup (changed when meeting large file uploading)
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
}
|
|
|
|
# ============================
|
|
# Root path redirect: Root -> /web/home
|
|
# ============================
|
|
location = / {
|
|
return 302 /web/home;
|
|
}
|
|
|
|
# Deny hidden files at root level
|
|
location ~ /\. {
|
|
deny all;
|
|
return 404;
|
|
}
|