Node.js前端程序通过Nginx部署后刷新出现404问题的解决办法

方案一 (这种方式容易被第三方劫持)

location / {
         root /data/nginx/html ;
         index index.html index.htm;
         error_page 404 /index .html;
}
方案二
location / {
     root /data/nginx/html ;
     index index.html index.htm;
     if (!-e $request_filename) {
         rewrite ^/(.*) /index .html last;
         break ;
     }
}
方案三 (vue.js官方教程里提到的 https://router.vuejs.org/zh-cn/essentials/history-mode.html
server {
     listen 80;
     server_name localhost;
     root /data/wwwroot/dist ;
     location / {
         try_files $uri $uri/ @router;
         index index.html index.htm;
     }
     location @router {
         rewrite ^.*$ /index .html last;
     }
}
参考以下两位大神的博客:
https: //blog .csdn.net /u011025083/article/details/80352301
https: //www .jianshu.com /p/02ad1f919471

猜你喜欢

转载自www.cnblogs.com/chenlianyong19890418/p/10150134.html