zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    读REDIS数据结构
    一致性哈希虚节点解决雪崩问题
    TCP的建立和关闭
    nginx和apache的比较
    进程和线程的区别
    acm过河卒
    搭建centos7 的php环境
    navicat 中 oracle数据传输到mysql上
    安装虚拟机精简版centos7
    整合tomcat的一些配置
  • 原文地址:https://www.cnblogs.com/gavin007/p/7929019.html
Copyright © 2011-2022 走看看