[PATCH 2 of 7] Fixed try_files with alias on case-insensitive systems
Maxim Dounin
mdounin at mdounin.ru
Fri Apr 17 22:45:37 UTC 2026
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1776465863 -10800
# Sat Apr 18 01:44:23 2026 +0300
# Node ID 27388647e0cdc914b874534d9342b4d59fe5cc68
# Parent 74f425f1c7650c29443503ef1934bbe20651c07f
Fixed try_files with alias on case-insensitive systems.
Previously, checking that try_files with variables matches an aliased
location was done using ngx_strncmp() rather than ngx_filename_cmp().
This works correctly in configurations with $uri, such as:
location /prefix/ {
alias /foo/;
try_files $uri =404;
}
But this can produce unexpected results on systems with case-insensitive
filesystems, such as Windows and macOS, when configuration-provided
variables are used to construct file names, such as the following
configuration, and assuming a request using different case, such as
"GET /Prefix/":
location /prefix/ {
alias /foo/;
set $maintenance "/prefix/maintenance.html";
try_files $maintenance $uri =404;
}
The fix is to use ngx_filename_cmp(), which properly ignores case on
relevant systems.
diff --git a/src/http/modules/ngx_http_try_files_module.c b/src/http/modules/ngx_http_try_files_module.c
--- a/src/http/modules/ngx_http_try_files_module.c
+++ b/src/http/modules/ngx_http_try_files_module.c
@@ -176,7 +176,7 @@ ngx_http_try_files_handler(ngx_http_requ
*e.pos = '\0';
if (alias && alias != NGX_MAX_SIZE_T_VALUE
- && ngx_strncmp(name, r->uri.data, alias) == 0)
+ && ngx_filename_cmp(name, r->uri.data, alias) == 0)
{
ngx_memmove(name, name + alias, len - alias);
path.len -= alias;
More information about the nginx-devel
mailing list