rewrite or internal redirection cycle while internally redirecting to "/index.html" (nginx) — how to fix
[error] 1234#1234: *1 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 203.0.113.5, server: example.com, request: "GET /about HTTP/1.1"
Quick fix: Make sure the fallback exists: ls $root/index.html. Fix root to point at the build folder (e.g. root /var/www/app/dist;), and use try_files $uri $uri/ /index.html; (or =404 as the last argument). Remove rewrite rules that match their own target, then sudo nginx -t && sudo systemctl reload nginx.
What it means
An internal redirect happens inside nginx without the browser seeing it: the last argument of try_files, an error_page, or rewrite ... last makes nginx restart location matching with a new URI. If that new URI leads back to another internal redirect, nginx loops. After 10 internal redirects it stops, logs this error and returns 500 Internal Server Error.
The message is in the error log, not the browser:
sudo tail -n 50 /var/log/nginx/error.log
Cause 1: the try_files fallback does not exist
The typical SPA config:
location / {
try_files $uri $uri/ /index.html;
}
If /index.html is not present under root, nginx tries the fallback, which is processed by the same location /, which falls back to /index.html again: a cycle.
Check what nginx is actually serving:
sudo nginx -T | grep -n "root"
ls -l /var/www/app/dist/index.html
Fix the root to the folder that contains the built index.html (often dist/ or build/, not the project folder), or run the build if the folder is empty.
server {
root /var/www/app/dist;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
If you want nginx to return 404 instead of looping when a file is missing, end try_files with =404:
location /assets/ {
try_files $uri =404;
}
Cause 2: permissions on the fallback file
If nginx cannot read index.html (or a parent directory lacks the execute bit), the lookup also fails. Check that the nginx worker user (www-data on Debian/Ubuntu, nginx on RHEL) can read the path:
sudo -u www-data stat /var/www/app/dist/index.html
Fix with chmod/chown (the chmod calculator helps with modes). On SELinux systems, check ls -Z for the right context.
Cause 3: a rewrite that matches its own result
location / {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
The rewritten /index.php matches location / again (if there is no location ~ \.php$ that catches it) and is rewritten again. Use break instead of last to stop processing rewrites in the current location, add a separate location for the target, or make the regex exclude the target.
Apply the change
sudo nginx -t
sudo systemctl reload nginx
Last updated 2026-12-02.