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

转载于:https://www.cnblogs.com/gavin007/p/7929019.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值