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

  • 相关阅读:
    CSS左侧固定宽 右侧自适应(兼容所有浏览器)
    MySQL学习笔记之一
    删除goagnt证书方法〔chrome
    JS通过ajax动态读取xml文件内容
    display vs visibility
    android SDK更新
    关于JS APP
    Ajax HTML, JS
    Request/Server模式
    关于SOAP
  • 原文地址:https://www.cnblogs.com/gavin007/p/7929019.html
Copyright © 2011-2022 走看看