How can I resolve the 500 internal server error Nginx when accessing a subpath like /busca.html?

I’m trying to debug a 500 internal server error nginx issue. When I access 127.0.0.1:6789, everything works fine. But if I try something like 127.0.0.1:6789/busca.html?q=a, I immediately get a 500 Internal Server Error.

Here’s a snippet from my nginx.conf:

location / { try_files $uri $uri/ /index.html; } And the log shows:

rewrite or internal redirection cycle while internally redirecting to “/index.html” I suspect it’s related to how try_files is configured, maybe causing a redirect loop. Has anyone faced a similar 500 internal server error nginx when using try_files for SPA-like routing? How can I resolve this properly without breaking other routes like /index.php or /404.html?

Been wrangling Nginx configs for over a decade now, seen this “500 internal server error nginx” too many times.

When you’re using:

try_files $uri $uri/ /index.html;

…and /index.html doesn’t exist, Nginx keeps looping. It’s like a fallback with no net. Double-check that /index.html is actually in your root folder.

location / {
    root /usr/share/nginx/html;  # This must contain index.html
    try_files $uri $uri/ /index.html;
}

Once I dropped the file in correctly, the 500 error? Gone.

Yep, ran into something similar. In my case, I was mixing an SPA with PHP routes, and bam, a classic 500 internal server error nginx.

Turns out, the fallback was too greedy. It tried handling .php requests like they were missing static files.

What worked for me? Splitting the logic:

location / {
    try_files $uri $uri/ /index.html;
}

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

Now, SPA fallback works and PHP routes don’t break. Clean, effective fix.

Ah yes, if you’re still seeing the 500 internal server error nginx after trying both those fixes, here’s a trick from my React/Vue deployments.

Sometimes, letting try_files handle everything causes internal rewrite loops. What helped? Defining an explicit named fallback.

location / {
    try_files $uri $uri/ @rewriter;
}

location @rewriter {
    rewrite ^ /index.html break;
}

This setup made routing predictable. /busca.html?q=test stopped crashing, PHP routes stayed safe, and I got full control over error handling.