Try_files and location blocks

Dave Hayes dave at jetcafe.org
Sat Jun 25 03:02:45 MSD 2011


appa at perusio.net writes:
> No. It doesn't. Check the code. It tries a named location otherwise
> invokes ngx_http_split_args(). That's just a concise way of writing a
> debug line in the error log.

Ok, I checked the code. As far as I can tell, it uses the actual
path output in the debug line. The code only calls the split_args()
thing is if tf->lengths == NULL and tf->name.len == 0...and also
if that is true then it appears to redirect:

        ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
                       "try to use %s: \"%s\" \"%s\"",
                       test_dir ? "dir" : "file", name, path.data);

        if (tf->lengths == NULL && tf->name.len == 0) {

            if (tf->code) {
                ngx_http_finalize_request(r, tf->code);
                return NGX_OK;
            }

            path.len -= root;
            path.data += root;

            if (path.data[0] == '@') {
                (void) ngx_http_named_location(r, &path);

            } else {
                ngx_http_split_args(r, &path, &args);

                (void) ngx_http_internal_redirect(r, &path, &args);
            }

            ngx_http_finalize_request(r, NGX_DONE);
            return NGX_OK;
        }
        ...
        if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
            != NGX_OK)
        {
   

If I'm correct (and I might not be) if split_args() gets called then
an internal redirect is done to that path.

I checked this two ways.

a) I compared the debug output of 

  try_files /error.php @some_other_location

  2011/06/24 15:40:33 [debug] 66904#0: *1 try files phase: 11
  2011/06/24 15:40:33 [debug] 66904#0: *1 try to use file: "/error.php" 
"/home/test/error.php"
  2011/06/24 15:40:33 [debug] 66904#0: *1 try file uri: "/error.php"
  
with 
  
  try_files /error.php?c=404 @some_other_location

  2011/06/24 15:39:05 [debug] 66770#0: *1 try to use file: "/error.php?c=403" 
"/home/test/error.php?c=403"
  2011/06/24 15:39:05 [debug] 66770#0: *1 try to use file:
"@real_error_403" "/home/test/@real_error_403"

b) I added to the code this:

+       ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "really truly try to use %s: \"%s\" \"%s\"",
+                       test_dir ? "dir" : "file", name, path.data);
        if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool)
  
So it's right above the open (which ostensibly does the file check).
This gives me:

  2011/06/24 16:00:15 [debug] 70121#0: *1 try files phase: 11
  2011/06/24 16:00:15 [debug] 70121#0: *1 try to use file: "/error.php?c=403" 
"/home/test/error.php?code=403"
  2011/06/24 16:00:15 [debug] 70121#0: *1 really truly try to use file: 
"/error.php?c=403" "/www/home/test/website/error.php?code=403"
  2011/06/24 16:00:15 [debug] 70121#0: *1 try to use file: "@real_error_403" 
"//home/test/@real_error_403"

Even with this evidence, I don't know the code all that well so if I'm
missing something please correct me. :) I am using nginx 1.0.3, maybe
that is the issue? 
-- 
Dave Hayes - Consultant - Altadena CA, USA - dave at jetcafe.org 
>>> The opinions expressed above are entirely my own <<<

The concept, the label, is perpetually hiding from us all
the nature of the real.                      --Joyce Cary






More information about the nginx mailing list