vue.js - 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;
}
解决方案
好吧,对于未来寻找这个的人来说,这就是解决方案。
在 Nginx 节点配置(您的后端)中添加:
error_page 404 =200 /index.html;
在位置块之前。这会将所有未找到的路径重定向到当前页面。
推荐阅读
- r - 为每个组添加计数器列
- algorithm - 需要帮助分析 O(n) 复杂度
- r - 嵌套 For 循环并将结果存储在 ?Vector? 中
- calayer - CALayer 未在 macCatalyst 中调整窗口大小时更新
- google-sheets - 如何引用在 Google 表格中写入公式的单元格?
- html - 为什么 text-align: center 对视频有效?
- ios - 如何从 NavigationController 中的 SwiftUI View 推送到 UIViewController
- c - 将 pcap_t* 文件描述符分配给内存块?
- java - 将本机查询映射到 pojo 类
- python - 是否可以使用 Python 3.x 在 tkinter 中使用 Scale 和 checkbutton 调用相同的函数?