HTTP Error 500 (Internal Server Error) means the web server hit an unexpected problem and could not complete the request. It is the generic, catch-all server error, and the fault is on the website's side, not in your browser or your connection.
If you are a developer, the 500 is only a symptom. The real error, usually an unhandled exception, a bad configuration value or a failed dependency such as the database, is sitting in a log somewhere. Find the log entry for the failing request and you have found the fix. Most of this article is about where those logs live on each stack and what the common messages mean. If you are just visiting a site that shows the error, the next section is all you need.
If you are a visitor
Only the site's owners can fix the real cause, but a few things are worth trying:
- Reload after 30 to 60 seconds. Many 500s are momentary, for example during a deployment.
- If the error appeared after you clicked Pay or Submit, don't resubmit blindly. Check your email or account first, because the action may have succeeded even though the page failed.
- Try a private or incognito window. If the page works there, clear that site's cookies and cache; a corrupted session cookie or a misbehaving extension can occasionally send a request the server cannot handle.
- Try another browser or device, and check the site's status page or social accounts for an outage notice.
- If it persists, contact the site with the time, the URL and what you clicked. That lets them find your request in their logs.
If every site gives you errors, the problem is your network. A single site returning 500 is almost always on their end, and it can last anything from a few seconds to hours during a real outage.
What a 500 tells you, and what it doesn't
RFC 9110, the HTTP specification, defines 500 as a response indicating that "the server encountered an unexpected condition that prevented it from fulfilling the request". In other words: something broke, and the server has no more specific code for it.
Browser sends request
↓
Server routes it to application code
↓
Code throws an exception, or config/dependency fails
↓
Nothing handles the error
↓
Server returns 500 Internal Server Error
It shows up in several costumes. Chrome and Edge say "This page isn't working. example.com is currently unable to handle this request. HTTP ERROR 500". IIS adds a sub-status code after a dot, as in "HTTP Error 500.30" or "500.19". WordPress says "There has been a critical error on this website". They all mean the same thing.
The neighbouring 5xx codes are more specific, and getting the code right tells you where to look first:
Code | Meaning | Where to look first |
|---|
500 Internal Server Error | The application or web server failed while processing the request | Application logs, exception stack trace |
502 Bad Gateway | A proxy got an invalid response, or no response, from the app behind it | Is the app process running? Did it crash at startup? |
503 Service Unavailable | The server is overloaded, in maintenance, or the app pool is stopped | App pool status, scaling, maintenance mode |
504 Gateway Timeout | The proxy gave up waiting for the app | Slow queries, slow external APIs, timeouts |
The distinction between 500 and 503 is worth holding onto: a 500 means the server tried to handle your request and failed, while a 503 means it is deliberately not handling requests right now and should recover on its own. For a wider look at the status line itself, see HTTP/1.1 500 Internal Server Error.
The checklist I'd run on any stack
Before you open stack-specific tooling, work through these in order:
- Reproduce it with the exact request. Use
curl -i https://yoursite/path, or copy the request from the DevTools Network tab with "Copy as cURL". Note the method, headers and body. - Ask what changed. A deployment, config change, package update, certificate renewal or database migration in the last hour is the prime suspect.
- Read the logs for that request, using the timestamp, path or trace ID. The stack trace usually names the file and line.
- Decide whether it is a startup failure or a request failure. If every URL fails, including static files, the app probably did not start. If only one endpoint fails, it is a code or data issue.
- Check configuration and secrets in the failing environment: environment variables, connection strings, key vault access, file paths.
- Test dependencies directly. Can the server reach the database host and port? Does the external API respond? Check permissions and disk space while you are there.
- Reproduce locally with production-like settings: the same environment name, config and data shape.
- If users are affected and the fix is not obvious, roll back first and debug afterwards.
- Fix it, add a test, and make the failure handled. Expected failures such as "not found" or "invalid input" should return a 4xx code, not a 500.
Step 4 is the fork in the road, so the rest of this article follows it.
Every URL fails: the app did not start
When every route returns 500 right after a deploy, the cause is almost always outside your request code: a missing environment variable or secret, a bad connection string, a missing DLL or package, the wrong runtime version, or a partial upload. Permissions are the other usual suspect, when the app pool identity or www-data cannot read config or write to a logs or uploads folder.
ASP.NET Core on IIS
If the app crashes during startup, nothing reaches your logging provider, so you need the ASP.NET Core Module's stdout log. Turn it on in web.config:
<aspNetCore processPath="dotnet"
arguments=".\MyApp.dll"
stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout"
hostingModel="inprocess" />
Create the logs folder yourself and give the app pool identity write access. Reproduce the error, read the newest stdout_*.log, then set stdoutLogEnabled="false" again. Microsoft warns that these logs have no size or file limit, so leaving them on can fill the disk.
Also check Event Viewer > Windows Logs > Application for entries from the ASP.NET Core Module. But the quickest test of all is to open a command prompt in the site folder and run dotnet .\MyApp.dll. Startup exceptions print straight to the console.
The sub-status code narrows things down further. Microsoft's ASP.NET Core troubleshooting guide for IIS and Azure App Service covers each one in depth; these are the ones you will meet:
Code | Meaning | Usual fix |
|---|
500.19 | Configuration data is invalid (web.config or applicationHost.config) | Install the .NET Hosting Bundle so IIS recognizes the aspNetCore section. Install the URL Rewrite module if web.config has rewrite rules. Fix malformed XML. |
500.30 | In-process startup failure | The app threw during startup. Read the stdout log or run dotnet MyApp.dll. Common causes: bad connection string, missing config, no access to key vault. |
500.31 | Failed to find native dependencies | Install the matching .NET runtime or Hosting Bundle |
500.32 | Failed to load DLL | Publish for the right architecture (x64 vs x86) and match the app pool's 32-bit setting |
500.34 and 500.35 | Mixed or multiple in-process apps in one app pool | Give each app its own app pool |
500.37 | App did not start within the startup time limit | Speed up startup, or stagger many apps starting at once |
502.5 | Process failure (out-of-process) | Target framework not installed, or the app crashes at launch |
500.19 is especially common when a Vue, React or Angular SPA is deployed to IIS with a rewrite rule but without the URL Rewrite module installed. Troubleshooting 404 or 500 Error After Deploying a Vue 3 App to IIS walks through that exact case.
Cloud hosts
Cloud platforms add a layer, but the rule is the same: find the application log for the failing request.
- On Azure App Service, use the Log stream, App Service logs, "Diagnose and solve problems" and the Application Insights failures view. For ASP.NET Core startup errors, the stdout log path is
\\?\%home%\LogFiles\stdout. - On AWS (EC2, ECS, Lambda, Elastic Beanstalk), check CloudWatch Logs for the app or function. A 502, 503 or 504 from the load balancer means the targets are unhealthy or slow, which is a different problem from a 500 your code returned.
- On Google Cloud Run and App Engine, filter Cloud Logging by the service and severity ERROR.
- On Vercel, Netlify and similar hosts, read the function or runtime logs for the deployment, and check that environment variables exist in the production scope, not just preview.
- Behind a CDN or WAF, first establish whether the error page is the CDN's or your origin's by hitting the origin directly.
One endpoint fails: an unhandled exception
When only some requests fail, you are usually looking at an unhandled exception in code (a NullReferenceException, an undefined property access, a division by zero) or a dependency failing for that request: a database that is down or rejecting the password, an external API returning errors, an expired certificate.
Seeing the exception in ASP.NET Core
Apps built with WebApplication.CreateBuilder show the Developer Exception Page automatically when the environment is Development, with the stack trace, query string, cookies and headers. Locally, make sure ASPNETCORE_ENVIRONMENT=Development is set in launchSettings.json. Never enable that page in production, because it exposes internals to anyone who triggers an error.
In production, logs are your exception page. The default providers write to the console, which most hosts capture, so make sure errors are not filtered out:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
And log exceptions with structured data, not just a message, so you can search by the values that matter:
catch (SqlException ex)
{
logger.LogError(ex, "Failed to load order {OrderId} for {UserId}", orderId, userId);
throw;
}
Returning a clean error from an API
An API should never answer a failure with an HTML error page or a raw stack trace. ASP.NET Core supports Problem Details (RFC 9457, which replaced RFC 7807), a standard JSON error format, and a few lines of setup give you consistent errors:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddProblemDetails();
builder.Services.AddExceptionHandler<GlobalExceptionHandler>();
var app = builder.Build();
app.UseExceptionHandler(); // unhandled exceptions become 500 ProblemDetails
app.UseStatusCodePages(); // empty 4xx/5xx responses get a ProblemDetails body
app.MapGet("/orders/{id:int}", (int id) =>
id <= 0 ? Results.Problem(statusCode: 400, title: "Invalid order id")
: Results.Ok(new { id }));
app.Run();
For central logging and mapping, implement IExceptionHandler (ASP.NET Core 8 and later):
using Microsoft.AspNetCore.Diagnostics;
public sealed class GlobalExceptionHandler(
ILogger<GlobalExceptionHandler> logger,
IProblemDetailsService problemDetails) : IExceptionHandler
{
public async ValueTask<bool> TryHandleAsync(
HttpContext context, Exception exception, CancellationToken ct)
{
logger.LogError(exception, "Unhandled exception on {Path}", context.Request.Path);
context.Response.StatusCode = StatusCodes.Status500InternalServerError;
return await problemDetails.TryWriteAsync(new ProblemDetailsContext
{
HttpContext = context,
Exception = exception,
ProblemDetails =
{
Title = "An unexpected error occurred.",
Status = StatusCodes.Status500InternalServerError
}
});
}
}
The client gets a predictable body with no internals. Include the trace identifier, so support can match a user's report to your logs:
{
"type": "https://tools.ietf.org/html/rfc9110#section-15.6.1",
"title": "An unexpected error occurred.",
"status": 500,
"traceId": "00-6f1c0e8a7b2d4c3e9f0a1b2c3d4e5f60-1a2b3c4d5e6f7a8b-00"
}
Just as important, don't use 500 for client mistakes. Return 400 for validation errors, 404 for missing resources, 409 for conflicts, and 401 or 403 for auth problems. A 500 should always mean "we have a bug or an outage". Keeping it that way makes 500 meaningful for alerting and tells clients whether a retry is worth it.
Node.js and Express
Start with the process output: pm2 logs, journalctl -u yourapp, docker logs <container> or your host's log viewer. Then make sure you have an Express error handler. It takes four arguments and goes after all routes. Express 5 automatically forwards rejected promises from async handlers to it; on Express 4 you must catch them and call next(err) yourself.
app.use((err, req, res, next) => {
if (res.headersSent) return next(err);
console.error({ path: req.path, err });
const status = err.status ?? 500;
res.status(status).type('application/problem+json').json({
title: status === 500 ? 'An unexpected error occurred.' : err.message,
status
});
});
Set NODE_ENV=production so the default handler does not send stack traces to users. And note that if the process crashes completely, the reverse proxy usually returns 502, not 500. Put it under a process manager or a container restart policy, then fix the crash.
A blank page or "critical error" in PHP and WordPress
With display_errors off, as it should be in production, a PHP fatal error becomes a blank 500 page. Check the PHP error log (the error_log setting, often visible in your hosting panel) or the web server's error log. The usual messages are:
- "Allowed memory size of ... bytes exhausted": raise
memory_limit, or fix the loop or query that loads too much. - "Call to undefined function": a missing PHP extension, or code written for a different PHP version.
- "Maximum execution time exceeded": a slow external call or query.
WordPress has its own recovery path. Check the admin email first, because WordPress sends a recovery-mode link when a plugin or theme causes a fatal error. Then enable logging in wp-config.php:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true ); // writes to wp-content/debug.log
define( 'WP_DEBUG_DISPLAY', false ); // don't show errors to visitors
If the log points at a plugin, rename wp-content/plugins/plugin-name over FTP or SSH to disable it. If you can't tell which plugin, rename the whole plugins folder and re-enable them one at a time. Do the same with the theme if the error is there. Regenerate .htaccess by going to Settings > Permalinks and clicking Save, and turn WP_DEBUG off when you are done.
The web server itself returns 500
Sometimes your application never runs at all, and Apache or Nginx produces the 500.
On Apache, a syntax error in .htaccess returns a 500 for the whole folder, and the error log names the exact line. Using RewriteEngine in .htaccess without mod_rewrite enabled does the same; on Debian or Ubuntu, run a2enmod rewrite and reload Apache. Validate configuration with apachectl configtest. The log is usually at /var/log/apache2/error.log on Debian and Ubuntu, or /var/log/httpd/error_log on the RHEL family.
On Nginx, validate with sudo nginx -t before every reload and read /var/log/nginx/error.log. A 500 generated by Nginx itself is often a "rewrite or internal redirection cycle", such as a try_files fallback pointing at a file that does not exist, or a "permission denied" on the web root. When Nginx is a reverse proxy, errors from the app usually pass through as 500 while a dead or slow app shows up as 502 or 504. In those cases debug the app, not Nginx, and hitting the app directly proves which side is failing:
sudo nginx -t
sudo tail -n 50 /var/log/nginx/error.log
curl -i http://127.0.0.1:5000/health # hit the app directly, bypassing Nginx
Resource limits round out the list on any server: PHP's memory_limit, a full disk, or too many open connections.
Don't let 500s linger
A 500 is more than a bad experience for one user. Google slows crawling when a site keeps returning 5xx errors, and URLs that return server errors for a long time can be dropped from its index. Short blips do little harm; a persistent one costs you traffic. Alert on 5xx spikes, keep 500 reserved for genuine bugs and outages, and make sure every one of them leaves a log entry with a trace ID you can find the next time it happens.
Join the conversation! Your thoughts help the community grow.