500 Internal Server Error
The server ran into something it did not expect and could not finish the request. The code says nothing about what went wrong; the server's own logs do.
What 500 means
A 500 is the catch-all of the 5xx class. The request reached the server, looked valid enough to act on, and then something broke: an unhandled exception, a crashed worker, a configuration the server could not parse. No more specific code applied, so the server sent this one.
That makes the status itself nearly useless for diagnosis. Whatever produced it also wrote a line to a log, and that line is where every 500 investigation starts. If you are a visitor rather than the owner, there is nothing on your side to fix.
Finding the real error
Look at the log of the component that generated the response, at the time of the request:
- Application log or error tracker. A framework turns an uncaught exception into a 500 and records the stack trace.
- nginx
error_log. nginx itself rarely originates a 500; when it does, the cause is usually a configuration loop, reported asrewrite or internal redirection cycle. - Apache
ErrorLog. A syntax error in.htaccessturns every request under that directory into a 500 and logsInvalid commandwith the offending directive. A CGI or FastCGI script that dies before printing headers logsEnd of script output before headers. - PHP. A fatal error with
display_errorsoff gives an empty 500. The message is in the PHP or PHP-FPM error log.
If the response passed through a proxy or CDN, check which layer wrote the body. A 500 with your framework's error page came from the application; a bare server-branded page came from the web server in front of it.
Common causes
- An unhandled exception: a null value where an object was expected, a failed type conversion, a missing key.
- A dependency that is down or refusing connections (database, cache, another API) and code that does not handle the failure.
- A deploy that left code and database schema out of step, or a missing environment variable or secret.
- Wrong file permissions or ownership after an upload or restore, so the server cannot read or execute the script.
- A full disk, or a process killed for exceeding its memory limit halfway through a request.
- A broken
.htaccessor a rewrite rule that redirects to itself.
If you call an API that returns 500
- Retry only requests that are safe to repeat (GET, PUT, DELETE, or a POST with an idempotency key), a small number of times with increasing delays. A 500 does not tell you whether the work was done before the failure.
- Do not treat it as a rate limit: there is no
Retry-Afterto honour, and hammering a failing endpoint makes things worse. - Record the response body and any request ID header. Those are what the API's support team will ask for.
- If the same input fails every time, the input is probably triggering a bug. Reduce it to the smallest request that still fails and report that.
If it is your server
- Return a specific code when the fault is the caller's. Validation failures belong in 400 or 422, missing records in 404. A 500 for bad input hides real faults among the noise.
- Use 503 with
Retry-Afterfor overload and planned maintenance, so clients and crawlers know the condition is temporary. - Keep stack traces, SQL and file paths out of the response body in production. Send a short message and a request ID, and log the detail.
- Alert on the 500 rate rather than on single events, and tie each one to a deploy: most bursts start within minutes of a release.
500 compared with 502, 503 and 504
| Code | Who failed | Typical meaning |
|---|---|---|
| 500 Internal Server Error | The application itself | A bug or misconfiguration; no better code applies |
| 502 Bad Gateway | The server behind a proxy | The proxy got no usable answer from it |
| 503 Service Unavailable | Nobody, exactly | Overloaded or in maintenance; try again later |
| 504 Gateway Timeout | The server behind a proxy | It did not answer within the proxy's time limit |
Example 500 response
HTTP/1.1 500 Internal Server Error
Content-Type: application/json
Content-Length: 54
{"error":"internal_error","request_id":"req_7f3a9c21"}Nothing about the cause is exposed. The request_id lets whoever runs the server find the matching log entry.
Defined in RFC 9110, section 15.6.1.
Questions
Is a 500 error my fault as a visitor?
Almost never. A 500 means the server failed while handling the request. Reloading once is reasonable; beyond that, only the site owner can fix it. If one particular action always triggers it, telling the site what you did helps them find the bug.
Is it safe to retry a request that returned 500?
For GET requests, yes. For requests that change data, only if repeating them is harmless or the API supports idempotency keys, because the server may have completed part of the work before it failed.
Are 500 responses cached?
Not by default. 500 is not one of the status codes a cache may store without explicit freshness information, so a browser or CDN keeps it only if the response carries headers such as Cache-Control: max-age.
Do 500 errors affect SEO?
Google slows its crawling when a site returns server errors and keeps already indexed pages for a while. URLs that keep returning 5xx are eventually dropped from the index, so a short outage does little harm and a long one does.