HTTP 500 · 5XX RFC 9110 §15.6.1 Cacheable: No Retryable: Only with caution (idempotent ops)

HTTP 500 Internal Server Error: Root Causes & Production Fix Guide

HTTP 500 Internal Server Error is the catch-all server crash code. Fast triage means correlating the request ID with application stack traces, missing environment variables, database connection errors, or broken `.htaccess` syntax.

Top Root Causes of HTTP 500

Safe Production 500 Handler (No Stack Trace Leak)

// Express.js global error middleware
app.use((err, req, res, next) => {
  const requestId = req.headers['x-request-id'] || crypto.randomUUID();
  console.error({ requestId, err });
  res.status(500).json({
    type: 'about:blank',
    title: 'Internal Server Error',
    status: 500,
    request_id: requestId,
  });
});

Verify with cURL

curl -i -sS -H 'X-Request-Id: debug-500-01' https://api.example.com/v1/checkout

Interactive Stack Diagnoser (HTTP 500)

Frequently Asked Questions

Why should I never return stack traces in a production 500 response?

Stack traces leak file paths, dependency versions, SQL queries, and internal secrets to attackers. Log them server-side and return only an opaque `request_id`.

How do I debug a 500 error in Nginx?

Check `/var/log/nginx/error.log` first, then your upstream app journal (`journalctl -u app -n 100`) or container logs (`docker logs`).

Can a missing environment variable cause 500 errors?

Yes—validate all required environment variables at startup so deployments fail fast before receiving live traffic.

Related Status Guides & Header Tools