我在nginx后面有一个dockerized VueJS应用程序。 VueJS路由器配置为历史记录模式:
const router = new Router({
base: __dirname,
mode: "history",
scrollBehavior,
routes: [
我主要从官方文档中提取的Docker文件
# https://vuejs.org/v2/cookbook/dockerize-vuejs-app.html#Real-World-Example
# build static files
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install --silent
COPY . .
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
# Add nginx config
COPY ./config/nginx/nginx.conf /etc/nginx/conf.d/app.conf
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
以及有关历史记录模式的nginx配置的说明:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /usr/share/nginx/html;
index index.html;
location / {
# Support the HTML5 History mode of the vue-router.
# https://router.vuejs.org/en/essentials/history-mode.html
try_files $uri $uri/ /index.html;
}
}
我正在本地运行映像,并且当我导航到根目录时一切正常,如果导航到子页面,则它也正常工作,只有刷新该页面后,我会得到404 Not Found - nginx/1.14.2
:(
我导出了Docker容器并检查了文件系统。 nginx配置已正确复制。 我还能做什么?
编辑:
经过stackoverflow的一些自动建议之后,我发现解决了这类问题的文章:https://stackoverflow.com/a/54193517/2289706
,我已经用COPY ./config/nginx/nginx.conf /etc/nginx/conf.d/default.conf
覆盖了默认值,但是现在的问题是,我不能将多个配置文件加载到nginx上吗? ?