前端平台后台用客户端路由 /admin/*,但 nginx 把 /admin/ 反代给了 Django(只有自带后台), 刷新 /admin/prompts 等 → Django 404。把 Django 后台挪 /django-admin/、nginx 同步改, /admin/* 落到 try_files → index.html(SPA 路由)。Django admin 命名空间仍是 admin,reverse 不变。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
69 lines
2.1 KiB
Nginx Configuration File
69 lines
2.1 KiB
Nginx Configuration File
server_tokens off;
|
|
charset utf-8;
|
|
|
|
# Backend (Django gunicorn) service inside the cluster.
|
|
upstream airshelf_api {
|
|
server airshelf-core-api:8000;
|
|
}
|
|
|
|
# Preserve the original scheme: traefik terminates TLS and forwards
|
|
# X-Forwarded-Proto=https; fall back to our own scheme if it's absent.
|
|
map $http_x_forwarded_proto $fwd_proto {
|
|
default $http_x_forwarded_proto;
|
|
"" $scheme;
|
|
}
|
|
|
|
server {
|
|
listen 80;
|
|
server_name _;
|
|
root /usr/share/nginx/html;
|
|
index index.html;
|
|
|
|
client_max_body_size 50m;
|
|
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
|
|
|
|
# ---- Backend pass-through (same origin, no CORS) ----
|
|
location /api/ {
|
|
proxy_pass http://airshelf_api;
|
|
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 $fwd_proto;
|
|
proxy_read_timeout 300s;
|
|
}
|
|
|
|
# Django 自带后台(已从 /admin/ 挪到 /django-admin/);/admin/* 留给前端 SPA 平台后台,走底部 try_files 回落 index.html
|
|
location /django-admin/ {
|
|
proxy_pass http://airshelf_api;
|
|
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 $fwd_proto;
|
|
}
|
|
|
|
# Django/WhiteNoise admin static assets
|
|
location /static/ {
|
|
proxy_pass http://airshelf_api;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Forwarded-Proto $fwd_proto;
|
|
}
|
|
|
|
# ---- Frontend SPA: hashed assets cache long, index.html never ----
|
|
location /assets/ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
location = /index.html {
|
|
add_header Cache-Control "no-cache, must-revalidate" always;
|
|
expires off;
|
|
}
|
|
|
|
# SPA fallback: every unknown path serves index.html (client-side routing)
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
}
|