From 51d5010c43e870615da77642007afe0058bdf903 Mon Sep 17 00:00:00 2001 From: seaislee1209 Date: Wed, 24 Jun 2026 02:04:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(admin):=20Django=20=E8=87=AA=E5=B8=A6?= =?UTF-8?q?=E5=90=8E=E5=8F=B0=E6=8C=AA=E5=88=B0=20/django-admin/,/admin/*?= =?UTF-8?q?=20=E5=9B=9E=E8=90=BD=20SPA,=E4=BF=AE=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=88=B7=E6=96=B0=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 前端平台后台用客户端路由 /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) --- core/backend/airshelf/urls.py | 4 +++- core/frontend/nginx.conf | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/backend/airshelf/urls.py b/core/backend/airshelf/urls.py index 0447e7e..fd948a9 100644 --- a/core/backend/airshelf/urls.py +++ b/core/backend/airshelf/urls.py @@ -5,7 +5,9 @@ from apps.common.views import health_check urlpatterns = [ - path("admin/", admin.site.urls), + # Django 自带后台挪到 /django-admin/:让前端 SPA 平台后台独占 /admin/*(否则 /admin/xx 刷新被 + # nginx 反代给 Django → 404)。Django admin 命名空间仍是 "admin",reverse 不受影响。 + path("django-admin/", admin.site.urls), path("api/health/", health_check, name="health-check"), path("api/auth/", include("apps.accounts.urls")), path("api/products/", include("apps.products.urls")), diff --git a/core/frontend/nginx.conf b/core/frontend/nginx.conf index 259698b..4863094 100644 --- a/core/frontend/nginx.conf +++ b/core/frontend/nginx.conf @@ -34,7 +34,8 @@ server { proxy_read_timeout 300s; } - location /admin/ { + # 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;