ProofDevs
Specialists for this

Server crash and gateway errors

Fix a crashing server, 502 or 504 gateway error

Free analysisNo commitment2 min

What is actually going on

502 and 504 responses describe a broken connection between a proxy and an upstream service, not one universal cause. The investigation needs application logs, Nginx or load-balancer logs, memory and CPU data, process limits, SSL configuration and the recent deploy history.

How the work runs

Step 01

Stabilize the incident

Confirm impact, preserve logs, use a safe rollback or restart only when necessary, and avoid repeated changes that erase evidence.

Step 02

Trace the failing boundary

Compare proxy, process manager, application and host signals to identify whether the upstream is dead, slow, unreachable or misconfigured.

Step 03

Prevent the next crash

Fix the cause, set sensible limits and health checks, and document deployment and recovery steps for the team.

What 502 and 504 actually tell you

A 502 usually means the proxy received an invalid response or could not connect to the upstream. A 504 usually means the upstream did not respond within the proxy timeout. Both are useful clues, but neither identifies whether the problem is code, memory, networking, configuration or a downstream dependency.

That is why changing the Nginx timeout immediately can hide a slow application instead of fixing it. Start by comparing timestamps across the proxy and application logs.

The server layers to inspect

A reliable diagnosis follows the request through each boundary so a restart is not mistaken for a solution.

  • DNS, TLS and the public load balancer or reverse proxy.
  • Nginx upstream settings, connection limits and timeout behaviour.
  • PM2, systemd, Docker or another process manager and its restart policy.
  • Application memory, event-loop stalls, worker counts and open connections.
  • Database, storage, payment or external API calls that hold requests open.
  • Host memory, disk space, file descriptors and kernel-level OOM events.

A restart is recovery, not root-cause analysis

Restarting a process can be an appropriate containment step during an outage, especially when the service is consuming all memory. It should be followed by evidence collection and a plan to reproduce or observe the condition before it happens again.

The final handoff should include a health check, a rollback command, alert thresholds and a clear owner for the hosting and deployment credentials.

Do not erase the incident

Capture logs and resource evidence before repeated restarts or log rotation remove the clues needed to explain the crash.

Useful evidence for a server-crash investigation

  • Exact time and frequency of the 502, 504 or connection-refused response.
  • Nginx, process-manager and application logs from the same incident window.
  • Memory, CPU, disk and network graphs, including swap and file-descriptor usage.
  • Hosting provider, operating system, runtime, reverse proxy and process manager.
  • The last deployment, configuration change or dependency update before the failure.

Common questions

Why does restarting the server fix a 502 temporarily?

A restart clears a crashed process, exhausted memory, stuck connection or temporary resource limit. It does not explain why that state occurred, so the same condition can return until logs and resource data are inspected.

Is a 504 always an Nginx problem?

No. A 504 means the proxy waited too long for an upstream response. The upstream application, database, network or external service may be the slow component.

Can a developer fix a server crash without changing hosting providers?

Often yes. The first investigation should check the current runtime, limits, processes and deployment before recommending a migration. Moving hosts without understanding the failure can reproduce it elsewhere.

Related