A secure home for your next big idea. Explore hosting →

Knowledgebase / Linux and Server Management

How to Troubleshoot a 502 Bad Gateway Error

Trace a 502 response from the public gateway to the application it depends on, using logs and controlled tests rather than repeated restarts.

Prerequisites

Record the affected URL, timestamp, timezone and any request identifier. Note whether every page fails or only a particular action does. Hosting customers need access to available error logs; service restarts and upstream configuration changes belong to the administrator responsible for the server.

A gateway sits between a visitor and another service. A 502 indicates that it could not obtain a valid upstream response. This differs from a missing page and does not by itself identify which application component failed.

Step 1: Establish the pattern

  1. Check a small static resource and a dynamic application page.
  2. Compare the public error with the provider’s service-status information.
  3. Record whether the failure is continuous, intermittent or tied to a slow operation.
  4. Correlate the exact request time with gateway and application logs.

If only dynamic requests fail, investigate the application runtime before changing public DNS. If an error appears only through a CDN, support may compare the origin and edge paths while retaining the correct hostname and TLS validation. Do not expose an origin address publicly or disable protections as a casual diagnostic step.

Step 2: Inspect the upstream

The responsible administrator should identify the configured upstream socket or network destination and check whether the intended service is listening. Connection refusal, a missing socket, an invalid response and an exhausted worker pool call for different repairs.

Check resource graphs, recent deployment changes and service logs. A process may be running but unable to handle work because of memory pressure, blocked dependencies or worker exhaustion. Increasing a timeout will not repair a crashed application or a wrong upstream address.

Step 3: Repair the confirmed cause

If a deployment introduced the failure, use its tested rollback procedure. If a runtime service failed, inspect the first relevant error before a controlled restart, and verify why it failed. Repeated restarts can hide evidence and interrupt healthy requests.

For configuration changes, use the server software’s configuration validation command and the provider’s reload procedure. Do not paste a generic service name or socket path into production: distributions, PHP versions and hosting panels choose different names.

When Cloudflare is involved, keep the timestamp and request details for support and distinguish origin-side failures from edge-side incidents. Do not assume the CDN caused the problem merely because its error page is visible.

Expected results and troubleshooting

Repeat the original failing action, then a normal page request. Confirm successful responses and inspect logs over several representative requests. If the failure occurs only under load, examine concurrency and slow dependencies rather than declaring success after one refresh.

A support report should include the route, timing, frequency and recent changes, with credentials and session identifiers removed. The expected result is a stable upstream response with the diagnosed cause corrected, not just a temporary disappearance of the error page.

Frequently asked questions

Is 502 always caused by Cloudflare?

No. A web-server reverse proxy or another gateway can return it too.

Will a longer timeout fix it?

Only a confirmed timeout-related configuration issue warrants that change. It does not fix a stopped upstream.

Should I restart every service?

No. Identify the failed dependency and use a controlled, documented recovery.

Related guides and hosting options

Compare server management against your application requirements. Confirm available tools and management responsibilities for your own account. For account-specific help, open a private support ticket with the domain, time and relevant redacted error.

Official references