其一般位于server location部分

location / {
            try_files $uri $uri/ /index.php?$args;

但不了解其中原理,尤其是$uri $uri $is_args $args的意义,直接粘贴就会发生诡异的HTTP 500错误


语法: 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 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/ /index.php?q=$uri&$args;


try_files 将尝试你列出的文件并设置内部文件指向。

try_files $uri /cache.php @fallback;

它将检测$document_root/app/cache/index.php,$document_root/app/cache/index.html 和 $document_root$uri是否存在,如果不存在着内部重定向到 @fallback 。
你也可以使用一个文件或者状态码 (=404)作为最后一个参数,如果是最后一个参数是文件,那么这个文件必须存在。
需要明确的是出最后一个参数外 try_files 本身不会因为任何原因产生内部重定向。

关于$uri $uri $is_args $args

try_files $uri $uri/ /index.php$is_args$args 或 try_files $uri $uri/ = 404


  • 参数: $uri
  • 解释: 表示当前请求的URI(域名后的内容),不带任何参数 例如访问:
  • $uri: "/about"
location / {
            try_files $uri $uri/ = 404


  1. 第一个参数$uri Nginx首先会查找/下有没有名为$uri的文件,本例中为名为demo的文件,如有则将请求传递给$uri
  2. 第二个参数$uri/ 如找不到名为$uri的文件,Nginx接着会查找/下有没有名为$uri的文件夹,本例中为名为demo的文件夹,如有则将请求传递给$uri/
  3. 第三个参数= 404 如前两个参数都无法接收请求 就返回状态码404
location / {
            $uri $uri/ /index.php$is_args$args





try_files $uri $uri/ /index.php/$uri;


Last modification:December 16th, 2018 at 03:31 am