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

  • 相关阅读:
    linux:yum
    python:公共操作
    python 控制流程
    linux:lamp环境
    linux:nginx
    深圳:永安在线-安全
    linux:mysql
    linux:shell
    linux:项目上线
    linux:权限管理
  • 原文地址:https://www.cnblogs.com/gavin007/p/7929019.html
Copyright © 2011-2022 走看看