Fix nginx 500: rewrite or internal redirection cycle (try_files)
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.
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.
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.
# nginx -T 2>/dev/null | grep -E '^\s*(root|try_files)'# ls -l /srv/www/public/index.html root /srv/www/public; try_files $uri $uri/ /index.html;ls: cannot access '/srv/www/public/index.html': No such file or directoryIf 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:
| Situation | What to check |
|---|---|
SPA build output (index.html) lives in another directory | does 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 deploys | does it happen only right after a deploy? |
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.
location / { try_files $uri $uri/ =404;}The same request now returns 404 instead of 500.
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.
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.
# nginx -t && systemctl reload nginx# curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1/no-such-pageApache 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.