HTTPQUERY
中文

500 Internal Server Error

Usage

The 500 Internal Server Error status code signals a generic failure on the server side. Due to the broad nature of this error, the specific cause depends on the environment. The web server is experiencing problems and the server administrator needs to take action to resolve the issue.

The error is often attributed to a permissions problem on one or more files, a script timeout, or corruption in the .htaccess file. The only certainty is the HTTP request was not fulfilled.

Example

The client requests a resource and the server responds with a 500 Internal Server Error status code, indicating the request will not be satisfied.

Request

GET /news.html HTTP/1.1
Host: example.com

Response

HTTP/1.1 500 Internal Server Error
Content-Type: text/html; charset=UTF-8
Content-Length: 139

<html>
  <head>
    <title>Request Failed</title>
  </head>
  <body>
    <p>The request failed due to a server error.</p>
  </body>
</html>

How to fix

Start with the error log. In nginx, check /var/log/nginx/error.log. In Apache, check /var/log/apache2/error.log or /var/log/httpd/error_log. The log entry almost always names the failing file and line number.

Common root causes and their fixes:

After identifying the cause, deploy the fix and monitor the error log for recurrence. Set up log alerting to catch 500 spikes before users report them.

Code references

.NET

HttpStatusCode.InternalServerError

Rust

http::StatusCode::INTERNAL_SERVER_ERROR

Rails

:internal_server_error

Go

http.StatusInternalServerError

Symfony

Response::HTTP_INTERNAL_SERVER_ERROR

Python3.5+

http.HTTPStatus.INTERNAL_SERVER_ERROR

Java

java.net.HttpURLConnection.HTTP_INTERNAL_ERROR

Apache HttpComponents Core

org.apache.hc.core5.http.HttpStatus.SC_SERVER_ERROR
org.apache.hc.core5.http.HttpStatus.SC_INTERNAL_SERVER_ERROR

Angular

@angular/common/http/HttpStatusCode.InternalServerError