GrepBoard/Manuals
605 manuals ·

Fix nginx 500: rewrite or internal redirection cycle (try_files)

·Tested on nginx 1.30.6 (Docker) · 2026-10·Test scope ↓·5 steps

A 500 with rewrite or internal redirection cycle means the last try_files target is missing under root. Create that file or end try_files with =404.

output
2026/10/27 00:59:13 [error] 14#14: *2 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 127.0.0.1, server: , request: "GET /no-such-page HTTP/1.1", host: "127.0.0.1:8080"

try_files sent a request for a missing URL to its last target (/index.html), that target does not exist under root either, so the request kept looping inside the same location until nginx stopped it. The client gets a 500. The name after while internally redirecting to is the file to check first.

Per the docs, try_files checks the files in order and, if none exist, makes an internal redirect to the last parameter. The redirected /index.html matches location / again and runs try_files again. nginx allows this loop at most 10 times and then fails the request.

[1] Read the target and the request from the error line. The line above is GET /no-such-page cut off while redirecting to /index.html. The access.log records a 500 at the same moment.

output
127.0.0.1 - - [27/Oct/2026:00:59:13 +0000] "GET /no-such-page HTTP/1.1" 500 177 "-" "curl/8.14.1" "-"

[2] Look at the effective root and try_files. nginx -T expands included files as well.

console
# nginx -T 2>/dev/null | grep -E '^\s*(root|try_files)'# ls -l /srv/www/public/index.html
output
    root /srv/www/public;        try_files $uri $uri/ /index.html;ls: cannot access '/srv/www/public/index.html': No such file or directory

If your last argument is something else, such as /index.php?$args, point ls at that file instead (/srv/www/public/index.php).

If root plus the last target is not a real file, that is the cause. Three common situations:

SituationWhat to check
SPA build output (index.html) lives in another directorydoes root point at the build directory (dist, build)?
fallback is /index.php but there is no location ~ \.php$without a PHP block, /index.php also matches location / and loops the same way (reproduced below)
typo in root, or the directory is swapped during deploysdoes it happen only right after a deploy?
output
2026/10/27 00:59:16 [error] 27#27: *2 rewrite or internal redirection cycle while internally redirecting to "/index.php", client: 127.0.0.1, server: , request: "GET /no-such-page HTTP/1.1", host: "127.0.0.1:8080"

[3] For a static site, end with a status code. A code is not a redirect, so no loop can form.

/etc/nginx/conf.d/site.conf
location / {   try_files $uri $uri/ =404;}

The same request now returns 404 instead of 500.

output
127.0.0.1 - - [27/Oct/2026:00:59:18 +0000] "GET /no-such-page HTTP/1.1" 404 153 "-" "curl/8.14.1" "-"

[4] If every URL must fall back to index.html (an SPA), put that file in root. With the file in place and the original config, the missing URL returned 200 with index.html.

output
127.0.0.1 - - [27/Oct/2026:00:59:20 +0000] "GET /no-such-page HTTP/1.1" 200 4 "-" "curl/8.14.1" "-"

For a PHP app, add a location ~ \.php$ { … fastcgi_pass …; } block in the same server so /index.php goes there. PHP-FPM errors after that are a separate step, such as Primary script unknown.

[5] Test, reload, and request one missing URL to confirm it is no longer 500.

console
# nginx -t && systemctl reload nginx# curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1/no-such-page

Apache reports the same kind of loop as AH00124; see AH00124 Request exceeded the limit of 10 internal redirects.

Analyze your Nginx log in the browser ↗ — nothing is uploaded.

#nginx#try_files#500#error-log