nginx.ccWeb server troubleshooting desk
Home / Errors / 500
500

Nginx 500: rewrite or internal redirection cycle

Short answer

“rewrite or internal redirection cycle” means the request was redirected internally more than 10 times and nginx gave up with 500. Most often the try_files fallback (say /index.html) does not exist and lands in the same location again. Check root and the entry file, then end the chain with =404.

Most common cause: try_files falls back to /index.html or /index.php but root points at the wrong directory, so the entry file is missing.

Try this first: End the fallback chain with =404

location / {
    root /var/www/site/dist;   # make sure index.html really is here
    try_files $uri $uri/ /index.html =404;
}

Last verified: · against the official docs listed below · Sources

Typical log lines

rewrite or internal redirection cycle while internally redirecting to "/index.html"
rewrite or internal redirection cycle while processing "/index.php"

Common causes

  1. try_files falls back to /index.html or /index.php but root points at the wrong directory, so the entry file is missing.
  2. A rewrite without last / break produces a URI that matches the same rule again.
  3. error_page points at a page that fails the same way.
  4. The front-end build was never uploaded (empty dist directory).

Diagnosis commands

Which URI it loops on
#grep 'redirection cycle' /var/log/nginx/error.log | tail -3
The directives involved
#nginx -T 2>/dev/null | grep -nE 'root|try_files|rewrite|error_page'
Does the fallback target exist
#ls -l /var/www/site/index.html

Fix configs

End the fallback chain with =404

location / {
    root /var/www/site/dist;   # make sure index.html really is here
    try_files $uri $uri/ /index.html =404;
}

Give rewrites last or break

location /blog/ {
    rewrite ^/blog/(.*)$ /index.php?p=$1 last;
}

Run nginx -t first, then systemctl reload nginx.

Key facts and sources

  • try_files checks only the parameters before the last one; the last one triggers an internal redirect or is =code. [nginx.org]
  • rewrite's last searches locations again with the new URI; break continues inside the current location. [nginx.org]

Checked against the linked pages on 2026-11-14; the official docs win if a newer nginx changes them.

FAQ

Why 500 and not 404?

nginx treats more than 10 internal redirects as a configuration error and returns 500. Once the path is fixed you get 200 or 404 as normal.

My SPA returns 500 on reload. Why?

Usually root does not point at the build directory (dist / build), so /index.html is missing. Fix root.

Fix it with a tool

Related errors

Sponsored slot (empty)
VPS / CDN recommendations may appear here later, labelled as affiliate links. There are no referral links today.