fix(admin): nginx.conf 与 deploy 对齐,避免 assets 回退为 HTML MIME 白屏

Made-with: Cursor
This commit is contained in:
whm
2026-03-23 17:00:27 +08:00
parent 0a1fe41314
commit 80176ea6fc
4 changed files with 35 additions and 2 deletions

View File

@@ -11,7 +11,7 @@ RUN npm run build
ARG REGISTRY_MIRROR=docker.m.daocloud.io/library/
FROM ${REGISTRY_MIRROR}nginx:alpine
COPY --from=builder /app/dist /usr/share/nginx/html
# 外层 Nginx 已把 /admin/ 转成 / 转发到本容器,故这里用 location / 提供 SPAbase 为 /admin/ 时静态资源请求为 /assets/...
RUN echo 'server { listen 80; root /usr/share/nginx/html; location / { try_files $uri $uri/ /index.html; } }' > /etc/nginx/conf.d/default.conf
# 与 deploy/admin/default.conf 同逻辑:^~ /assets/ 避免缺失 chunk 时回退到 index.html → MIME text/html 白屏
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

24
admin/nginx.conf Normal file
View File

@@ -0,0 +1,24 @@
# 与 deploy/admin/default.conf 保持一致Compose 挂载该文件;镜像内也用此配置)
# 外层 Nginx 已把 /admin/ 转成 / 转发到本容器,此处 location / 提供 SPA
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
# 发版后勿长期缓存入口,否则浏览器保留旧 index.html、却拉新 chunk 名 → 白屏
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 / {
try_files $uri $uri/ /index.html;
}
}