I'm using try_files like this:
http { server { error_log /var/log/nginx debug; listen 127.0.0.1:8080; location / { index off default_type application/octet-stream; try_files /files1$uri /files2/$uri /files3$uri; } } }
In the error log, it's showing this:
*[error] 15077#0: 45399 rewrite or internal redirection cycle while internally redirecting to "/files1/files2/files3/path/to/my/image.png", client: 127.0.0.1, server: , request: "GET /path/to/my/image.png HTTP/1.1", host: "mydomain.com", referrer: "http://mydomain.com/folder"
Can anyone tell me why nginx is looking for /files1/files2/files3/path/to/my/image.png
instead of /files1/path/to/my/image.png
, /files2/path/to/my/image.png
and /files3/path/to/my/image.png
?
Thanks
http://nginx.org/r/try_files
The last parameter specifies return code or URI for internal redirect. In your case it's
/files3$uri
.Perhaps you actually want this:
try_files /files1$uri /files2$uri /files3$uri =404;
I suspect that nginx is essentially recursing, because the paths specified in
try_files
are matched by thelocation /
block, which applies thetry_files
directive again. Try adding these location blocks to catch the paths which are being searched.The issue was solved by adding a root directive outside the location block: