zoukankan      html  css  js  c++  java
  • nginx中try_files

    location / {
                try_files $uri $uri/ /index.php?$query_string;
    }

    当用户请求 http://localhost/example 时,这里的 $uri 就是 /example。 
    try_files 会到硬盘里尝试找这个文件。如果存在名为 /$root/example(其中 $root 是项目代码安装目录)的文件,就直接把这个文件的内容发送给用户。 
    显然,目录中没有叫 example 的文件。然后就看 $uri/,增加了一个 /,也就是看有没有名为 /$root/example/ 的目录。 
    又找不到,就会 fall back 到 try_files 的最后一个选项 /index.php,发起一个内部 “子请求”,也就是相当于 nginx 发起一个 HTTP 请求到 http://localhost/index.php。 

    例子 2

    loaction / {
    
    try_files $uri @apache
    
    }
    
    loaction @apache{
    
    proxy_pass http://127.0.0.1:88
    
    include aproxy.conf
    
    }

    try_files方法让Ngxin尝试访问后面得$uri链接,并进根据@apache配置进行内部重定向。

    当然try_files也可以以错误代码赋值,如try_files /index.php = 404 @apache,则表示当尝试访问得文件返回404时,根据@apache配置项进行重定向。

  • 相关阅读:
    jQuery 笔记
    centos 项目上线shell脚本
    linux关于用户密码家目录总结
    python 写了一个批量拉取文件进excel文档
    css 选择器/table属性/type 属性
    表单
    html table
    html超文本标记语言
    mysql数据库1
    mysql数据库
  • 原文地址:https://www.cnblogs.com/boundless-sky/p/9459775.html
Copyright © 2011-2022 走看看