参照:http://www.nginx.cn/279.html
try_files
语法: try_files file ... uri 或 try_files file ... = code
默认值: 无
作用域: server location
按顺序检查文件是否存在,返回第一个找到的文件。结尾的斜线表示为文件夹 -$uri/。如果所有的文件都找不到,会进行一个内部重定向到最后一个参数。
try_files /app/cache/ $uri /index.php;
index index.php index.html;
它将检测$document_root/app/cache/index.php
,$document_root/app/cache/index.html
和 $document_root$uri是否存在,
如果不存在着内部重定向到
/index.php 。
try_files /app/cache/ $uri @fallback;;
index index.php index.html;
重定向到另外一个服务器
try_files /app/cache/ $uri =500;;
index index.php index.html;
返回状态码
备注:这个函数试试会进行内部重定向,可以和 deny 等配合使用(rewrite 等如果和deny一起使用将没有效果)