vue-cli3打包后上传服务器,浏览器刷新报nginx 404的问题

项目完成之后,npm run build打包上传服务器,从页面正常跳转没有问题,一刷新就会发现vue项目会报nginx404的报错。

84a4d55a68dd24fb09ca0a37b50b140.jpg

解决方案如下,配置nginx

   location / {

    root   /root/pc;

 if ($http_user_agent ~* "(mobile|nokia|iphone|ipad|android|samsung|htc|blackberry)") {
            root  /root/phone;
     }
        index  index.html index.htm;
         #核心
        try_files $uri $uri/ @router;
     }
    #核心
     location @router {
         rewrite ^.*$ /index.html last;
     }
    
    #核心
    error_page  404              /index.html; 

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。