You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker部署Vue.js页面刷新出现Nginx 404错误求助

Vue项目Docker部署后刷新子路由出现404问题

已参考Stack Overflow上关于「Vue.js搭配Nginx使用」的提问并尝试解决方案,但问题仍未解决。

问题现象

  • Docker镜像构建完成后,访问localhost:8080可正常显示,页面刷新无异常
  • 导航至localhost:8080/add_app时首次加载正常,但刷新该页面会出现404错误
    404错误截图
  • Docker Desktop中的错误信息:
    Docker错误截图

Dockerfile配置

# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY ./platform-frontend/package*.json ./
RUN npm install
COPY ./platform-frontend .
RUN npm run build

# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
COPY --from=build-stage /app/nginx/nginx.conf /etc/nginx/conf.d/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

Nginx配置文件(nginx.conf)

server {
    listen      80;
    server_name localhost;   
        
    location / {
        root /app/dist;
        index   index.html index.html;
        try_files $uri /index.html;
    }    
}

项目结构

项目结构截图

内容的提问来源于stack exchange,提问作者senadk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.08 21:50:24