Skip to main content

How to Troubleshoot a 502 Bad Gateway Error on a Website

A 502 Bad Gateway error occurs when one server on the internet receives an invalid response from another server it is attempting to access. This typically indicates a communication failure between a proxy server (such as Nginx, Apache, or a CDN) and...

A 502 Bad Gateway error occurs when one server on the internet receives an invalid response from another server it is attempting to access. This typically indicates a communication failure between a proxy server (such as Nginx, Apache, or a CDN) and the backend application server or service.

Before you begin

You will need:

  • Access to your website's hosting control panel or management interface.

  • Access to your website's backend (e.g., WordPress admin dashboard, if accessible).

  • The ability to perform basic troubleshooting of your website's configuration.

Check the status of the backend service

A 502 error often means the backend service (such as PHP-FPM, Apache, or a specific application service) is not running or is unresponsive.

  1. Log in to your hosting control panel.

  2. Locate the section for Server Management or Application Status.

  3. Check the status of the services related to your website, such as PHP-FPM or Web Server.

  4. If a service is listed as "Stopped" or "Down," attempt to restart it via the control panel.

Check for a hung or crashed process

Sometimes a specific script or process may hang, causing the gateway to time out or return an invalid response.

  1. Identify the specific page or action that triggers the 502 error.

  2. If the error occurs only on a specific page, it may be caused by a script that is exceeding the allowed execution time or memory.

  3. Restart the PHP service or the web server service to clear hung processes.

Verify the configuration of your proxy or load balancer

If you use a proxy service (like Cloudflare) or a local proxy (like Nginx), a configuration error can cause a 502 error.

  1. Check your proxy configuration files (e.g., nginx.conf or .htaccess).

  2. Ensure the "proxy_pass" or "fastcgi_pass" addresses are correct.

  3. If using a CDN, temporarily bypass the CDN by pointing your DNS directly to the origin server to determine if the issue is with the CDN or the origin server.

Check for a full disk or memory exhaustion

If the server runs out of available memory or disk space, it may be unable to spawn the processes required to serve your website.

  1. Check your account's resource usage in your control panel.

  2. If disk space is at 100%, delete unnecessary files or logs.

  3. If memory is exhausted, optimize your site or reduce the number of active processes.

Confirm the validity of your configuration files

A syntax error in a configuration file can cause the web server to fail when trying to pass the request to the backend.

  1. Check your .htaccess file (for Apache) or your site's configuration file (for Nginx).

  2. Ensure there are no extra characters or incorrect paths.

  3. If you recently made changes to these files, revert them to the previous version to see if the error resolves.

Confirm the result

  • The website loads successfully when navigating to the URL that previously displayed the 502 error.

  • The error is no longer visible in the browser or for other users.

If the error persists after these steps

If you have verified that your services are running, your disk space is sufficient, and your configuration files are correct, the issue may be deeper within the server's networking or software stack.

Collect the following information and contact Hostek support:

  • The specific URL(s) where the 502 error occurs.

  • A screenshot of the error page.

  • The time of day the error first appeared.

  • A list of any recent changes made to your website, plugins, or server configuration.

Did this answer your question?