脚本更新、配置更新
This commit is contained in:
+2
-2
@@ -8,11 +8,11 @@ RUN npm config set registry https://registry.npmmirror.com && npm ci
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
|
||||
# Stage 2: serve with nginx
|
||||
# Stage 2: serve with nginx(含 SPA 路由回退配置)
|
||||
FROM nginx:1.27-alpine AS serve
|
||||
|
||||
COPY --from=build /app/dist /usr/share/nginx/html
|
||||
# 自定义 nginx 配置由外层 docker-compose 挂载,这里只 serve 静态产物
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
@@ -0,0 +1,19 @@
|
||||
# 前端容器内部 nginx —— 负责 SPA 路由回退
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# 关键:所有找不到的路径回退到 index.html(Vue Router history 模式必需)
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# 静态资源缓存
|
||||
location /assets/ {
|
||||
expires 30d;
|
||||
add_header Cache-Control "public, immutable";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user