HTTP 5xx Server Errors: Meaning, Diagnosis and Fixes
DIRECT ANSWER
An HTTP 5xx response means a server or intermediary could not complete an otherwise valid request. Identify the exact status code and the layer that generated it—application, origin server, proxy, load balancer or CDN—then compare timestamps, logs, health checks and resource metrics. Repeated browser refreshes usually will not fix the underlying problem.
Key takeaways
- 500 usually indicates an error while the application or server was processing the request.
- 502 usually means a gateway or proxy received an invalid or unusable response from an upstream service.
- 503 indicates that the service is temporarily unable to handle the request, often because of maintenance, overload or an unhealthy dependency.
- 504 means a gateway or proxy did not receive an upstream response before its timeout.
- A branded proxy or CDN error page can show that the origin did not generate the response.
- Timestamps, request IDs, response headers and correlated logs are more useful than repeated refreshes.
Site Administrator
What this error means & how to recognize it
You may see one or more of these symptoms:
- A website or API returns an HTTP status from 500 through 599.
- The response is a generic server error, an application error, or a branded reverse-proxy, load-balancer or CDN page.
- Only one route, operation or API endpoint fails while other pages continue to work.
- The entire service becomes unavailable or intermittently returns errors.
- Requests become slow before ending with a 504 or another gateway-related 5xx response.
- The response includes a request ID, upstream identifier or server-specific error header that can help identify the generating layer.
Root causes, ordered by likelihood
Likely causes, from common to less common, include:
- Application exceptions or failed request handling. Unhandled application errors, invalid input paths or a faulty code change can produce a 500 response.
- Recent deployment or configuration changes. A release, environment-variable change, routing change or server configuration error may affect one route or the whole service.
- Unhealthy backend processes. A stopped, crashing, overloaded or unreachable application process can cause a proxy to return 502 or 503.
- Dependency failures. Database errors, unavailable internal services, slow external services or exhausted connection pools can surface as several different 5xx codes.
- Timeouts between layers. A gateway may return 504 when an upstream service does not respond within the configured timeout; slow dependencies can be the underlying cause.
- Resource pressure. High CPU or memory use, worker saturation, disk exhaustion or connection limits can make a service unavailable or cause requests to time out.
- Maintenance or intentional protection. A service may return 503 while it is being maintained, drained, rate-limited or protected from overload.
- Layer-specific status behavior. The same underlying incident can produce different codes depending on whether the application, web server, reverse proxy, load balancer or CDN generated the response.
How to fix it
1. Capture the failure precisely
Record the exact status code, affected URL or API operation, time including time zone, frequency, response body and relevant response headers. Preserve any request ID or trace ID. If you are only visiting the site, send these details to the service owner rather than changing server settings.
2. Identify the response-generating layer
Compare the error page or JSON body, headers, cookies and server identifiers with a known successful response. A framework-specific error body may point to the application; a gateway- or CDN-branded page may mean the request failed before the origin produced a response. Check reverse-proxy, load-balancer or CDN logs when origin logs contain no matching request.
3. Separate a broad outage from a route-specific failure
Test an approved, low-impact health endpoint and a known unaffected route. If only one route fails, inspect its application code, data access and request-specific dependencies. If every route fails, prioritize process health, deployment state, routing, capacity and shared dependencies. Do not repeatedly refresh a production endpoint as a substitute for a health check.
4. Correlate logs at the same timestamp
Review application, web-server, proxy/load-balancer and dependency logs together. Search for the request ID first, then narrow by timestamp and endpoint. Look for stack traces, process restarts, connection-refused messages, upstream status codes, timeout messages, failed database calls and rejected connections. Sanitize credentials, tokens and sensitive request data before sharing logs.
5. Check recent changes and service health
Review deployments, feature flags, configuration changes, certificate or routing updates, maintenance activity and dependency changes made shortly before the failures began. Confirm that backend processes are running and passing their health checks. If a recent change is strongly correlated with the incident, use the service's approved rollback procedure and authorization; do not restart or roll back production systems without operational approval.
6. Check dependencies and resource pressure
Inspect database reachability and latency, internal service health, external dependency responses, connection-pool usage, queue depth, CPU, memory, disk space, worker availability and connection limits. A dependency that is merely slow can cause a 504 even when the application process itself is running. Correct the constrained or failing component rather than masking the symptom by increasing timeouts blindly.
7. Use the status code to focus the investigation
- 500 Internal Server Error: Start with application logs, server errors, the failing route and recent code or configuration changes.
- 502 Bad Gateway: Inspect the proxy-to-upstream connection and the upstream response. Check whether the backend is down, closing connections, returning malformed data or being reached through an incorrect route.
- 503 Service Unavailable: Check maintenance state, readiness or health checks, overload controls, process availability and shared dependencies.
- 504 Gateway Timeout: Measure where time is spent. Check upstream latency, database or external calls, connection pools and timeout settings across each layer.
- Other 5xx statuses: Use the exact status definition and the component that emitted it; do not assume that every 5xx response has the same cause.
8. Apply the narrowest authorized fix and verify safely
Fix the identified application, configuration, dependency or capacity issue using the environment's change-control process. Afterward, verify a simple health endpoint, the previously failing operation and representative dependent functions. Confirm that 5xx rates and latency have returned to normal without creating duplicate writes or additional load. If the fix involves a state-changing action such as restarting a process, draining traffic or changing a timeout, document the expected impact and obtain authorization first.
Prevention & how to verify the fix
- Monitor 5xx rate, latency and availability by route, service and response-generating layer.
- Use readiness and liveness checks that reflect real dependency requirements without creating excessive load.
- Keep request IDs or trace IDs consistent across proxies, applications and dependencies.
- Set bounded, reviewed timeouts and connection limits at each service boundary; avoid allowing slow external calls to consume all workers.
- Alert on resource saturation, process crashes, database latency, connection-pool exhaustion and disk pressure before they become widespread failures.
- Use staged deployments, health-based traffic shifting and a tested rollback procedure.
- Document which 5xx codes each proxy, application and dependency can emit so responders do not treat 500, 502, 503 and 504 as interchangeable.
- Regularly test degraded-dependency and overload behavior in an authorized environment.
When to get outside help
Escalate to the service owner or on-call team when errors are widespread, continue after a recent change, affect authentication or payments, risk duplicate or incomplete writes, or involve possible data loss or corruption. Escalate sooner when the failing layer cannot be identified or recovery would require an unapproved restart, rollback, routing change or timeout change.
Include the exact status, affected endpoint, start and end times, frequency, request or trace IDs, response headers, recent changes, scope of impact and sanitized logs or metrics. Do not share passwords, API keys, session tokens, authorization headers or sensitive request bodies.
Frequently asked questions
Does a 5xx error mean the website is down?
Not necessarily. A 5xx response may affect one route, one dependency or a subset of requests. Check whether a health endpoint and unrelated routes succeed before treating it as a complete outage.
What is the difference between a 500 and a 502?
A 500 is generally generated while the application or server handles the request and encounters an error. A 502 is generally generated by a gateway or proxy that received an invalid or unusable response from an upstream service.
What is the difference between a 502 and a 504?
A 502 means the gateway received an unusable upstream response or could not use the upstream connection. A 504 means the gateway waited for an upstream response but its timeout expired. The same backend incident can sometimes lead to either code depending on what happened at the connection boundary.
Can overload cause a 503 response?
Yes. A service may return 503 during overload, maintenance, traffic draining or an unavailable dependency. Confirm the reason in service health, capacity metrics and logs rather than assuming every 503 has the same cause.
Why do proxy or CDN error pages matter?
They help identify the response-generating layer. If the proxy or CDN produced the page, the origin may not have received the request or may not have responded in time. Check intermediary logs and compare them with origin access logs.
Should I keep refreshing a 5xx page?
Usually not. Repeated refreshes rarely reveal the cause and can add load or repeat a state-changing request. Capture the error details and contact the service owner, or inspect correlated logs and health data if you operate the service.
Further documentation
- MDN Web Docs — HTTP server error responses — status-code overview and browser-facing HTTP guidance.
- RFC 9110 — HTTP Semantics — normative HTTP semantics, including server error response definitions.
For implementation-specific behavior, consult the documentation for the web server, reverse proxy, load balancer, CDN, application framework and hosting platform that generated the response. Their timeout, health-check and upstream-error behavior can differ.