Skip to content

500 Internal Server Error

Something went wrong on the server and it could not complete the request. It is a generic error and not your fault.

What 500 Internal Server Error means

500 is the catch-all server error. The app hit an unexpected condition, usually an unhandled exception, and had no more specific code to send.

The problem is on the server side, so changing your request rarely helps. The real cause is almost always in the server's error logs.

Common causes

  • An unhandled exception or bug in the application code.
  • A failed database connection or query.
  • A server misconfiguration, such as a broken .htaccess rule or wrong permissions on a script.
  • Missing environment variables or a half-finished deploy.

How to fix 500 Internal Server Error

  1. As a visitor, reload after a minute, and contact the site if it keeps happening.
  2. Check the application and web server error logs for the stack trace at the time of the request.
  3. Roll back the latest deploy or config change if the errors started right after it.
  4. Catch expected errors and return specific codes (400, 404, 503) so real 500s stand out.

Example response

HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8

500 Internal Server Error

How to check for a 500 response

cURL

# Print only the status code
curl -s -o /dev/null -w "%{http_code}\n" https://example.com/

JavaScript (Node.js)

const res = await fetch("https://example.com/");
if (res.status === 500) {
  console.log(res.status, res.statusText);
}

Python

import requests

res = requests.get("https://example.com/")
if res.status_code == 500:
    print(res.status_code, res.reason)

Go

res, err := http.Get("https://example.com/")
if err != nil {
	log.Fatal(err)
}
defer res.Body.Close()
if res.StatusCode == 500 {
	fmt.Println(res.Status)
}

Specification

500 Internal Server Error is defined in RFC 9110, section 15.6.1.

  • 502

    Bad Gateway

    A server acting as a gateway or proxy got an invalid response, or no usable response, from the upstream server behind it.

  • 503

    Service Unavailable

    The server cannot handle the request right now, usually because it is overloaded or down for maintenance. Try again later.

  • 504

    Gateway Timeout

    A gateway or proxy waited too long for a response from the upstream server and gave up before the page was ready.

← all 63 HTTP status codes

Type to search posts, tools and projects.

Keyboard shortcuts

Search+Kor/
Go to homegthenh
Go to bloggthenb
Go to projectsgthenp
Go to timelinegthent
Show this help?
Close search or helpesc