fix(nginx): admin 对齐 assets 配置;443 显式 /admin/assets/ 反代

Made-with: Cursor
This commit is contained in:
whm
2026-03-23 18:04:23 +08:00
parent 7980c1922a
commit ee9394f410
3 changed files with 28 additions and 2 deletions

View File

@@ -14,3 +14,4 @@
1. **确认 Nginx 配置已更新**`deploy/admin/default.conf` 须含 `location ^~ /assets/``try_files $uri =404`(与仓库内 `admin/nginx.conf` 一致),挂载后重启 `admin` 容器。 1. **确认 Nginx 配置已更新**`deploy/admin/default.conf` 须含 `location ^~ /assets/``try_files $uri =404`(与仓库内 `admin/nginx.conf` 一致),挂载后重启 `admin` 容器。
2. **确认 dist 完整**`deploy/admin/dist/assets/` 下须有与 `index.html``<script type="module">` 引用**同名**的哈希文件;发版后应**整目录**替换 `dist`(勿只拷 `index.html`)。 2. **确认 dist 完整**`deploy/admin/dist/assets/` 下须有与 `index.html``<script type="module">` 引用**同名**的哈希文件;发版后应**整目录**替换 `dist`(勿只拷 `index.html`)。
3. **本地重建**:在项目根按 `pull-and-restart.sh` 方式在 `admin/` 执行 `npm run build``vite.config``base` 须为 `'/admin/'` 3. **本地重建**:在项目根按 `pull-and-restart.sh` 方式在 `admin/` 执行 `npm run build``vite.config``base` 须为 `'/admin/'`
4. **勿用旧版 `nginx/admin.conf`**:若曾把仅含 `location /` 的旧配置拷到服务器,会导致 `/assets/*.js` 全部变成 `index.html`(约 640B、MIME 错)。请以 **`deploy/admin/default.conf`** 或 **`admin/nginx.conf`** 为准,并 **`docker compose restart admin nginx`**。

View File

@@ -1,9 +1,22 @@
# 供 compose 中 admin 容器使用:宿主机挂载 admin/distSPA 回退 # 与 deploy/admin/default.conf、admin/nginx.conf 保持一致(勿再使用仅含 location / 的旧版,否则 /assets/*.js 会回退成 index.html → 白屏)
# 外层 Nginx 把 /admin/ 转成 / 转发到本容器 # 外层 Nginx 把 /admin/ 转成 / 转发到本容器
server { server {
listen 80; listen 80;
root /usr/share/nginx/html; root /usr/share/nginx/html;
index index.html; index index.html;
location = /index.html {
add_header Cache-Control "no-cache, no-store, must-revalidate";
expires -1;
}
location ^~ /assets/ {
try_files $uri =404;
access_log off;
expires 7d;
add_header Cache-Control "public, immutable";
}
location / { location / {
try_files $uri $uri/ /index.html; try_files $uri $uri/ /index.html;
} }

View File

@@ -26,6 +26,18 @@ server {
add_header Cache-Control "no-store"; add_header Cache-Control "no-store";
} }
# ^~ location /strip /admin rewrite+break upstream web
location ^~ /admin/assets/ {
rewrite ^/admin/(.*)$ /$1 break;
set $upstream_admin admin;
proxy_pass http://$upstream_admin:80;
proxy_http_version 1.1;
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 / { location / {
set $upstream_web web; set $upstream_web web;
proxy_pass http://$upstream_web:80; proxy_pass http://$upstream_web:80;