Vue.js Nginx显示404,但vue cli提供路由服务
我已使用vue cli开发了我的应用程序。它似乎可以捕获任何URL请求,并且Vue能够处理它。例如,当我进入时http://localhost:8080/prihlaseni 在Chrome中,页面被渲染 我最近尝试使用Nginx为内容提供服务,并为NodeJS后端做反向代理。但是这次这个URLhttp://localhost/prihlaseni 返回Nginx错误404。如何将其修复为vue处理此URLVue.js Nginx显示404,但vue cli提供路由服务,vue.js,nginx,Vue.js,Nginx,我已使用vue cli开发了我的应用程序。它似乎可以捕获任何URL请求,并且Vue能够处理它。例如,当我进入时http://localhost:8080/prihlaseni 在Chrome中,页面被渲染 我最近尝试使用Nginx为内容提供服务,并为NodeJS后端做反向代理。但是这次这个URLhttp://localhost/prihlaseni 返回Nginx错误404。如何将其修复为vue处理此URL server { listen 80; server_nam
server {
listen 80;
server_name localhost;
location / {
index index.html index.htm;
root C:\dev\mezinamiridici\spa\dist;
}
location /api/ {
proxy_pass http://127.0.0.1:3000/;
}
}
您应该将nginX配置为捕获所有不存在的路径,并将它们重写为
index.html
location / {
try_files $uri @rewrite;
root C:\dev\mezinamiridici\spa\dist;
}
location /api/ {
proxy_pass http://127.0.0.1:3000/;
}
location @rewrite {
rewrite ^(.*)$ /index.html last;
}
谢谢,我将使用root指令更新您的答案,使其生效。