【发布时间】:2021-04-07 21:57:36
【问题描述】:
我有一个带有历史模式的 VueJS 应用程序。我的网站是 example.com,我的应用程序的基本 URL 是 my-app,当您使用 example.com/my-app 进入我的应用程序时,它可以完美运行,您可以浏览页面。不幸的是,当您尝试直接访问具有特定路由的页面时,我遇到了 404。
这是我的 nginx 配置文件:
...
server_name example.com;
root /var/www/apps;
index index.html
try_files $uri $uri/ /index.html;
...
我在 vueJS 文档中找到了最后一行。
这是我的路由器配置:
const router = createRouter({
base: process.env.VUE_APP_PUBLICPATH,
history: createWebHistory(process.env.BASE_URL),
routes,
});
还有.env.production 文件:
NODE_ENV=production
BASE_URL=/my-app/
VUE_APP_PUBLICPATH=/my-app/
我以为我正确地遵循了文档,但事实并非如此,因为当我检查 Nginx 日志时,出现以下错误:
2020/12/31 17:05:21 [error] 21351#0: *16 open() "/var/www/apps/index.html" failed (2: No such file or directory), client: XXX.XXX.XXX.XXX, server: example.com, request: "GET /my-app/about HTTP/1.1", host: "example.com"
谁能帮帮我?在此先感谢:)
【问题讨论】:
标签: vue.js nginx vuejs3 html5-history