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配置项进行重定向。

    我们只需要努力,然后剩下的交给时间。
  • 相关阅读:
    1167E (尺取法)
    Report CodeForces
    Maximum Xor Secondary CodeForces
    Sliding Window POJ
    单调队列 Sliding Window POJ
    尺取法
    目标
    NOIP系列(续)
    NOIP系列
    近期目标
  • 原文地址:https://www.cnblogs.com/lgj8/p/14512462.html
Copyright © 2011-2022 走看看