About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
The visitor gets a 500 Internal Server Error and the nginx error log has a line that contains rewrite or internal redirection cycle while internally redirecting to "/index.php". nginx follows a request through up to 10 internal redirects, and this request kept being sent back to a location that sent it on again. Our own reading of nginx's try_files text quoted below: a try_files whose last parameter, /index.php, does not exist under the location's root sends the request back to the same location, and that repeats.
What the error means
nginx's documentation for the internal directive says: "There is a limit of 10 internal redirects per request to prevent request processing cycles that can occur in incorrect configurations. If this limit is reached, the error 500 (Internal Server Error) is returned. In such cases, the “rewrite or internal redirection cycle” message can be seen in the error log."
In nginx 1.26.2 the limit is the constant NGX_HTTP_MAX_URI_CHANGES, set to 10 in ngx_http_request.h. Each URI change counts down from a starting value, and when it reaches zero nginx logs at the error level and finalises the request with a 500. The text ends differently depending on how the request got there. The source has three forms:
while processing "...", when arewritedirective keeps changing the URI;while internally redirecting to "...", when atry_filesorindexorerror_pagesends the request to another URI, as with/index.phphere;while redirect to named location "...", when the target is a named location such as@wordpress.
nginx adds the client address, the server name and the request after the message. The text between the quotation marks is the URI the request was being sent to when the limit was hit.
Three directives of the documentation matter here. The page for try_files begins "Checks the existence of files in the specified order and uses the first found file for request processing" and continues: "If none of the files were found, an internal redirect to the uri specified in the last parameter is made." The redirect starts a new search for a matching location. If that search lands in the same location and the file is still missing, the same redirect happens again. The rewrite flag last "starts a search for a new location matching the changed URI". And index has the same effect: "using an index file causes an internal redirect, and the request can be processed in a different location."
Likely causes
| Cause | What you see | How to confirm |
|---|---|---|
The last parameter of try_files, such as /index.php, is not found under the location's root and no other location catches it |
... while internally redirecting to "/index.php" |
The file named by root plus the URI does not exist |
No location for .php files, so /index.php lands in the location / that sent it there |
The same, even though PHP is installed | The server block has no location ~ \.php$ or its include is not loaded |
A rewrite ... last inside a location that matches its own result |
... while processing "..." |
nginx's page says to use break in a location, "or otherwise nginx will make 10 cycles and return the 500 error" |
A named location whose own try_files points back at the first one |
... while redirect to named location "@..." |
Read the two locations together |
Wrong root, for example after a deploy that moved the site |
Worked before the move; fails for every URL that does not exist as a file | Compare the root path with where the site files are |
Prove the cause before changing anything
All of these steps only read.
1. Find the lines. The error_log directive names the file. Use the file your configuration names; the path below is the one used in the example. The GNU manual says "grep prints lines that contain a match for one or more patterns."
grep "internal redirection cycle" /var/log/nginx-error.log
A good result is one or more lines with one of the three endings above, at the times of the failing requests. Note the URI in quotation marks.
2. Dump the configuration nginx is really using. nginx's page says -T is "same as -t, but additionally dump configuration files to standard output (1.9.2)", so it prints included files too.
nginx -T
In the output, find the server block for the host and read its root, index, every location, and every try_files. Look for a location that handles \.php$.
3. Check the file the redirect points at. nginx's page says "A path to the file is constructed by merely adding a URI to the value of the root directive", so the file to look for is the root value followed by the URI. The ls(1) page describes -l as "use a long listing format".
ls -l /var/www/example.com/public/index.php
A bad result is No such file or directory. A good result lists the file, in which case the cycle comes from the location search and not the missing file; read the locations again.
4. Optional: see each change. With rewrite_log on, nginx logs rewrite results "into the error_log at the notice level", and a debugging log (built with --with-debug and set with error_log ... debug) records each URI change; the 1.26.2 source writes a debug line uri changes: %d.
Fix
The cycle is broken at the place found above. There are three shapes of fix.
- Where the file is missing, either the
rootdoes not hold the site, which the edit below corrects, orindex.phpwas never deployed, which is for the site's developer to put in place. - Where the redirect lands in the wrong location, nginx's documented WordPress and Joomla example gives
.phpfiles their own location. It haslocation / { try_files $uri $uri/ @wordpress; }, a separatelocation ~ \.php$that begins withtry_files $uri @wordpress;, and a named location@wordpressthat passes to the PHP handler with/index.phpas the script. That is a description of nginx's example for the site's developer, with the PHP handler address and script path of the site's own setup; it is not a step to paste. - Where a
rewrite ... lastis the cause, nginx's page says thelastflag "should be replaced by break" inside alocation. That edit is made with the step below: changelasttobreakon that one line and leave the rest of the line as it is.
A root fix and a last to break fix are edits to a live server configuration, and the step below is how either is made.
First save the current state. The GNU manual says "cp copies files (or, optionally, directories)." Copy the file that holds the server block to /root/, which no include line reads, so nginx does not read the saved copy as configuration:
cp -p /etc/nginx/conf.d/example.com.conf /root/example.com.conf.2026-12-04
Risk: the next edit changes how a live site finds its files or routes its requests. A wrong root can break every page of the site, and a syntax error can stop the reload that follows. Edit the file when traffic is low, and do not reload until the syntax check passes.
Edit the file. For the case where root is wrong, the root line is changed to the directory that holds index.php:
root /var/www/example.com/current/public;
Check the syntax and file access. nginx's page describes -t as "test the configuration file: nginx checks the configuration for correct syntax, and then tries to open files referred in the configuration."
nginx -t
Disruptive step: the next command reloads nginx. nginx's guide says the master process checks the new file and, if it works, starts new worker processes and asks the old ones to shut down; if the check fails it "rolls back the changes and continues to work with the old configuration". Requests in flight are finished by the old workers.
nginx -s reload
Only if you need to back out: copy /root/example.com.conf.2026-12-04 back over example.com.conf.
Risk: the back-out command overwrites the live server file with the saved copy. It discards your edit and any other change made to the file since, so the cycle returns if the cause is still there.
cp -p /root/example.com.conf.2026-12-04 /etc/nginx/conf.d/example.com.conf
Check the restored file:
nginx -t
Disruptive step: the next command reloads nginx so that it loads the restored file. As above, the old workers finish requests in flight.
nginx -s reload
Example (illustrative): on web01, www.example.com has root /var/www/example.com/public;, index index.php;, and one location / { try_files $uri $uri/ /index.php?$args; } with no .php location. A deploy has moved the site to /var/www/example.com/current/public. A request for /hello finds no file, try_files redirects to /index.php, ls -l /var/www/example.com/public/index.php says the file does not exist, and the request comes back to location / ten times. The log shows while internally redirecting to "/index.php". The administrator saves the file, changes root to the new path, runs nginx -t, then nginx -s reload.
Confirm the fix
- Request the URL that failed, with
curl -I https://www.example.com/hello(curl's manual says-I, --headwill "Fetch the headers only."), and expect the status the application gives, not 500. - Look at the end of the error log: no new
internal redirection cycleline should appear after the reload. - Request
/index.phpand a static file that exists, such as an image, and check that each returns what it did before.
What to watch afterwards
- After every deploy that moves a site, run
nginx -Tand compare therootwith the real path before reloading. - Count
internal redirection cyclelines per day in the error log; a rise after a configuration change points straight at it. - Our own advice: whenever
try_filesends in a URI, read where that URI will land next and make sure a differentlocationtakes it.
Read next
Related articles you may want next.
- Troubleshootingnginx and PHP-FPM "File not found." and "Primary script unknown": SCRIPT_FILENAME and rootnginx and PHP-FPM 'File not found.' or 'Primary script unknown': check SCRIPT_FILENAME, root, chroot and that PHP-FPM sees the same path as nginx.Read article
- HostingApache AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration errorApache AH00124: request exceeded the limit of 10 internal redirects. Find the looping RewriteRule, stop the loop with [END] or conditions, and confirm.Read article
- Hostingnginx warning: conflicting server name "example.com" on 0.0.0.0:80, ignorednginx: conflicting server name on 0.0.0.0:80, ignored. Two server blocks claim one name. Find both with nginx -T, keep one, test and reload safely.Read article
Risks and limits
- These commands have not been run or lab-tested.
- The three message endings, and the limit of 10, come from nginx 1.26.2; other versions may count differently.
- The
nginx -Toutput includes the whole configuration, which can contain private paths and keys' file names. Our own advice: keep it out of public places. - Other messages look similar but have another cause. A page that says
File not found.instead of a 500 is covered in nginx and PHP-FPM "File not found." and "Primary script unknown": SCRIPT_FILENAME and root. The Apache form of this fault is the subject of Apache AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error.
Sources
- Module ngx_http_core_module — nginx, no date shown, accessed 4 December 2026
- Module ngx_http_rewrite_module — nginx, no date shown, accessed 4 December 2026
- Module ngx_http_index_module — nginx, no date shown, accessed 4 December 2026
- Command-line parameters — nginx, no date shown, accessed 4 December 2026
- Beginner’s Guide — nginx, no date shown, accessed 4 December 2026
- A debugging log — nginx, no date shown, accessed 4 December 2026
- nginx/src/http/ngx_http_core_module.c at release-1.26.2 — nginx source at a fixed tag, no date shown, accessed 4 December 2026
- nginx/src/http/ngx_http_request.h at release-1.26.2 — nginx source at a fixed tag, no date shown, accessed 4 December 2026
- nginx/src/http/ngx_http_request.c at release-1.26.2 — nginx source at a fixed tag, no date shown, accessed 4 December 2026
- cp invocation — GNU Coreutils 9.12 manual, no date shown, accessed 4 December 2026
- GNU Grep 3.12 — GNU Grep manual, no date shown, accessed 4 December 2026
- ls(1) — Linux manual page — Linux man-pages project, no date shown, accessed 4 December 2026
- curl man page — curl project, no date shown, accessed 4 December 2026
This article was originally published on .