【发布时间】:2021-06-05 05:51:58
【问题描述】:
我在 Ubuntu 服务器上有一个项目,在刷新或手动输入 URL 时会产生 404 错误。例如,我可以访问 example.com,但无法访问 example.com/home 或在该页面上刷新而不会收到 404。单击链接按预期工作。我在历史模式下使用 Vue 路由器,并在 nginx.conf 文件的 http 部分添加了以下内容:
server {
listen 80;
server_name example.com;
root /var/www/example.com;
location / {
try_files $uri $uri/ /index.html;
}
}
我可以使用 sudo nginx -t 测试配置并通过,但我仍然收到 404 错误。值得一提的是,我在此服务器上有多个服务器块。
【问题讨论】:
-
为什么不在
location /行之前添加index index.html -
是的,我最终发现我需要这样做。现在工作正常。
标签: nginx vue-router