[PATCH 0 of 7] try_files fixes
Maxim Dounin
mdounin at mdounin.ru
Fri Apr 17 22:45:35 UTC 2026
Hello!
The following patch series addresses multiple issues as observed with
the "try_files" directive, notably when used with "alias" or when
requests are proxied after "try_files". Changes include:
- Both variables and static strings in "try_files" arguments are now
handled consistently and expected to be in URI space, matching the
documentation. Previously, static strings in prefix locations with
alias were interpreted as an addition to alias. With this change,
configuration like this:
location /prefix/ {
alias /foo/;
try_files /prefix/bar =404;
}
will actually try the "/foo/bar" file, and not "/foo/prefix/bar",
matching what "try_files $uri" does with a request to "/prefix/bar".
- In regex locations with alias, "try_files $uri ..." is now properly
supported. Previously, only adding extensions worked in such
locations, as in "try_files .html ...". Also, using try_files in such
locations now produces correct URI.
- Proxying with URI replacement after try_files now aware if URI was
modified by try_files, and the following configuration will not corrupt
URI in requests to backend (or segfault, if URI is shorter than the
location prefix), but rather will avoid URI replacement (similarly to
what happens after rewrites):
location /prefix/ {
try_files /prefix.../test =404;
proxy_pass http://backend/remote/;
}
- Proxying after try_files now uses URI modified by try_files even if
original unparsed URI is still available, so the following configuration
will consistently use the ".html" extension in requests to the backend:
location / {
try_files $uri.html =404;
proxy_pass http://backend;
}
Review and testing appreciated.
--
Maxim Dounin
More information about the nginx-devel
mailing list