[PATCH] http_core: Do not match a file for a directory in try_files

Damien Tournoud damien at commerceguys.com
Tue Jan 20 23:54:40 UTC 2015


# HG changeset patch
# User Damien Tournoud <damien at commerceguys.com>
# Date 1421796392 -3600
#      Wed Jan 21 00:26:32 2015 +0100
# Node ID c8f2fbe53f5df811dcaada94d3eca6c34070c610
# Parent  0a198a517eaf48baad03a76b182698c50496d380
http_core: Do not match a file for a directory in try_files.

A try_files directive with a file match (i.e. something
not ending with a "/") does not match a directory of
the same name.

But a try_files directive with a directory match like this:

  try_files $uri/ =404;

... does currently match a *file* of the same name.

This doesn't break any test, so I assume this is not the
expected behavior. I have a separate changeset to extend
the test coverage.

This makes it impossible to target generic locations for
index-expansion only like this "allow only html files,
but perform index expansion":

  location / {
    try_files $uri/ =404;
    index index.html;
  }
  location ~ "\.html$" {
  }

diff -r 0a198a517eaf -r c8f2fbe53f5d src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c	Wed Jan 14 09:03:35 2015 +0300
+++ b/src/http/ngx_http_core_module.c	Wed Jan 21 00:26:32 2015 +0100
@@ -1353,7 +1353,7 @@
             continue;
         }
 
-        if (of.is_dir && !test_dir) {
+        if (of.is_dir != test_dir) {
             continue;
         }
 



More information about the nginx-devel mailing list