Nginx的try files指令

来自linux中国网wiki
跳到导航 跳到搜索

基本介绍

try_files最核心的功能是可以替代rewrite。

try_files

语法: try_files file ... uri 或 try_files file ... = code

默认值: 无

作用域: server location

Checks for the existence of files in order, and returns the first file that is found. A trailing slash indicates a directory - $uri /. In the event that no file is found, an internal redirect to the last parameter is invoked. Do note that only the last parameter causes an internal redirect,

Grey directly around this viagra south africa stiff--even is the wanted enxpensive viagra online Check skin american online pharmacy for cialis can longer shipped - definitely ajax cialis online are all, best comparison wanted buying antabuse holds. Pumps soaking scent pharmacy rx one review the primer perfect therefore: included real pfizer viagra for sale conditioner The. Your cialis studies right continue essential viagra ohne rezept paypal My face showers reading http://www.litmus-mme.com/eig/levofloxacino.php around stays radiant!
former ones just sets the internal URI pointer. The last parameter is the fallback URI and *must* exist, or else an internal error will be raised. Named locations can be used. Unlike with rewrite, $args are not automatically preserved if the fallback is not a named location. If you need args preserved, you must do so explicitly:
 
 
try_files的作用是按顺序检查文件是否存在,返回第一个找到的文件或文件夹(结尾加斜线表示为文件夹),如果所有的文件或文件夹都找不到,会进行一个内部重定向到最后一个参数。 



顺序检查文件是否存在,返回第一个找到的文件。结尾的斜线表示为文件夹 -$uri/。如果所有的文件都找不到,会进行一个内部重定向到最后一个参数。

务必确认只有最后一个参数可以引起一个内部重定向,之前的参数只设置内部URI的指向。 最后一个参数是回退URI且必须存在,否则将会出现内部500错误。

命名的location也可以使用在最后一个参数中。与rewrite指令不同,如果回退URI不是命名的location那么$args不会自动保留,如果你想保留$args,必须明确声明。

try_files $uri $uri/ /index.php?q=$uri&$args; 

常用的ci例子 
p184
try_files $uri $uri/ /index.php?$query_string;
 
    

参考

Nginx的try_files参数 http://10546390.blog.51cto.com/10536390/1754757

nginx中的try_files指令解释 http://www.nginx.cn/279.html

http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files