I am trying to set up try_files, but am running into an issue: It seems the fallback "empty.png" file is not picked up, even though it is located at /path/to/old_cache_data/empty.png
. The files that actually exist (i.e. no fallback) are found without problems. Also interesting enough I am not getting an nginx 404, but the 404 page from the app that is handled by the proxy_pass below.
Stuff I tried so far:
- Removing the leading slash, which lead to this curious error:
open() "/usr//htmlempty.png" failed (2: No such file or directory)
, Seems weird to me as /usr/html is not specified anywhere as any sort of fallback path.
- Specifying an absolute path (i.e.
try_files $uri /path/to/old_cache_data/empty.png;
)
Relevant rules:
# legacy static cache
location /cache/ {
root /path/to/old_cache_data;
try_files $uri /empty.png;
}
# pass-through
location / {
[bunch of proxy-settings]
proxy_pass [the target url];
}
So, not sure where exactly I'm "holding it wrong". It seems like try_files
does not pick up on the root
in the location but somehow does a weird fallback.
EDIT: I found out that placing the empty.png in the "cache" sub-folder and changing the try_files to try_files $uri /cache/empty.png;
actually works. I do not understand why this is the case though.