首页 > 解决方案 > Nginx 重定向与 vue 不工作 - 404

问题描述

编辑:我正在使用 proxy_pass 为我的节点后端提供服务,例如:

 location / {
   allow all;
 }

 location /backend {
      proxy_pass http://localhost:60702;
      # Some headers
 }

删除此文件时,它可以按我的意愿工作。为什么这部分会导致所有错误?


好吧,现在我在 Vue/nginx 中遇到了一些重定向问题。

现在我用 nginx 托管 vue 并将根目录设置为/var/www/client/pvapp-client/dist. 在输入 URL 的某些路径时,例如“https://url.de/pathname”,我得到的错误相当于:

*2 open() "/var/www/client/pvapp-client/dist/app" failed (2: No such file or directory)

为什么要像这样检查 dist 中的目录?它应该保持在同一页面上或重定向到 vue 中指定的路径,例如router.push('/home')

Nginx conf 位置块是:

location / {
   # point to dist folder inside vue source code folder
   root /var/www/client/pvapp-client/dist;
   autoindex on;
   autoindex_exact_size off;
   index index.html index.htm;
   try_files $uri $uri/ /index.html;
}

标签: vue.jsnginxredirect

解决方案


好吧,对于未来寻找这个的人来说,这就是解决方案。

在 Nginx 节点配置(您的后端)中添加:

error_page 404 =200 /index.html;

在位置块之前。这会将所有未找到的路径重定向到当前页面。


推荐阅读