nginx history路由模式时,页面返回404重定向index.html


1.路由默认是带#的,有时我们感觉不美观,就使其变为history模式,也就没有#字符

2.# 如果找不到当前页面(404),就返回index.html,重新分配路由

location ^~/prodTest/ {
    root C:/Users/Administrator/Desktop/gavinApp/testVue/my-project;
    try_files $uri /prodTest/index.html =404;
    expires 2h;
}

3.实例:如果用户请求路径为: http://localhost:8070/prodTest/login

此时 $uri == /prodTest/login

定义 $document_root == C:/Users/Administrator/Desktop/gavinApp/testVue/my-project

首先会找 $document_root /prodTest/login下的文件 =>

nginx 会返回 404 =>

nginx 会逐次找 try_files 对应值路径下的文件 

找 $uri 也就是 $document_root /prodTest/login  又找不到,

然后就会 fall back 到 try_files 的下一个配置项  /prodTest/index.html  也就是相当于 nginx 发起一个 HTTP 请求到  $document_root/prodTest/index.html

 

注:nginx 中 try_files 的理解  http://www.cnblogs.com/begin00/p/5491410.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM