Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Nginx显示404,但vue cli提供路由服务_Vue.js_Nginx - Fatal编程技术网

Vue.js Nginx显示404,但vue cli提供路由服务

Vue.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

我已使用vue cli开发了我的应用程序。它似乎可以捕获任何URL请求,并且Vue能够处理它。例如,当我进入时http://localhost:8080/prihlaseni 在Chrome中,页面被渲染

我最近尝试使用Nginx为内容提供服务,并为NodeJS后端做反向代理。但是这次这个URLhttp://localhost/prihlaseni 返回Nginx错误404。如何将其修复为vue处理此URL

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指令更新您的答案,使其生效。