From 00b35b891bc5a0463771dc51f037d796dc250f46 Mon Sep 17 00:00:00 2001 From: zyc <1439655764@qq.com> Date: Thu, 29 Jan 2026 15:27:41 +0800 Subject: [PATCH] fix router bug --- Dockerfile | 2 +- nginx.conf | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index 49655b0..759911d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ FROM nginx:stable-alpine AS production-stage COPY --from=build-stage /app/dist /usr/share/nginx/html # Copy custom nginx config if needed, otherwise default is used -# COPY nginx.conf /etc/nginx/conf.d/default.conf +COPY nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..71dc3e2 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,23 @@ +server { + listen 80; + server_name localhost; + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + # 解决 SPA 路由刷新 404 的关键配置 + try_files $uri $uri/ /index.html; + } + + # 静态资源缓存配置 (可选优化) + location /assets/ { + root /usr/share/nginx/html; + expires 7d; + add_header Cache-Control "public"; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +}