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

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;
    }
}

或者

location / {
    try_files $uri $uri/ /index.html;
}

参考以下两位大神的博客:

https://blog.csdn.net/u011025083/article/details/80352301
https://www.jianshu.com/p/02ad1f919471

  

相关文章:

  • 2022-12-23
  • 2021-10-08
  • 2022-02-27
  • 2022-02-19
  • 2021-07-17
  • 2021-09-09
  • 2022-12-23
  • 2022-02-09
猜你喜欢
  • 2022-12-23
  • 2022-01-16
  • 2021-09-10
  • 2021-06-29
  • 2021-09-05
  • 2022-12-23
相关资源
相似解决方案