Help

How to fix the 502 Bad Gateway error

“502 Bad Gateway” means a server that passes requests on, such as a CDN or the web server in front of PHP, got an invalid answer from the server behind it. Visitors can wait a minute and reload. Site owners should check that the server and PHP are running, then the CDN, DNS and firewall.

Updated · HostUpIndia team

What does 502 Bad Gateway mean?

A 502 comes from a gateway or proxy, not from the server that builds the page. The CDN, load balancer or web server in front asked the server behind it for the page and got a broken answer, or none at all.

The page can read “502 Bad Gateway”, “502 Proxy Error”, or “Bad gateway” with “Error code 502” on Cloudflare. If the server sends no page of its own, Chrome shows “This page isn’t working” and Edge “This page isn’t working right now”, both with “HTTP ERROR 502”. Firefox may show a blank page.

Similar errors have other causes. A 504 means the server behind took too long: see how to fix the 504 Gateway Timeout error. A 503 means the server is up but too busy: see how to fix the 503 error.

  • The server behind the proxy is down or restarting.
  • PHP, such as PHP-FPM, or the site’s app crashed, was restarted or ran out of workers.
  • A script ran so long that it was stopped before it answered.
  • A firewall blocks the CDN’s IP addresses.
  • The CDN’s DNS record points at the wrong IP address.
  • A plugin, theme or code change crashes PHP.

If you are visiting the site

A 502 is almost always on the website’s side. These checks rule out your device and network.

  • Wait a minute, then reload the page once.
  • Open the page in a private window or another browser.
  • Clear your browser’s cached files: in Chrome, Edge or Firefox, press Ctrl+Shift+Delete (Cmd+Shift+Delete on a Mac), select only the cache, and clear it.
  • Turn off any VPN or proxy, then reload.
  • Try another network, such as mobile data instead of Wi-Fi.
  • If the 502 shows everywhere, the site’s server is at fault. Try again later or tell the site’s owner.

If it is your website: find the cause

Narrow it down before you change anything. The logs are listed by time, so start with when it happened.

  • Note the time the 502 appeared and the page that showed it.
  • Read the error page. A Cloudflare page shows which part failed: the browser, Cloudflare or the host. A plain page often names the proxy, such as nginx.
  • Load an image or other static file on the site. If it loads but PHP pages fail, the problem is PHP or the app.
  • Check your email and client area for a maintenance or outage notice from your host.
  • In cPanel, open Metrics › Errors and read the entries from the time of the 502.
  • In File Manager, open the error_log file in your site’s folder, usually public_html, if there is one.
  • If the site uses a CDN, pause it for the site and reload after a few minutes.
  • If the 502 stops, the link between the CDN and your server is at fault. If it stays, the cause is on your server.

Fix a 502 from a CDN, DNS or firewall

A CDN gives a 502 when it cannot get a proper answer from your server. Check where it sends traffic and that your server lets it in.

  • Find your server’s IP address in your welcome email or client area.
  • In the CDN’s DNS or origin settings, note the current records, so you can undo a change.
  • Check that the A records for the domain and for www point to that IP address. Fix any old or mistyped address.
  • If there is an AAAA record your host did not give you, delete it.
  • In cPanel, open IP Blocker and remove any block on the CDN’s IP ranges. The CDN publishes its list.
  • In File Manager, open Settings and turn on Show Hidden Files (dotfiles).
  • Download a copy of .htaccess, then remove any rule that denies the CDN’s addresses.
  • Check any security plugin or firewall app on the site for blocks on the CDN.
  • If the CDN connects to your server over HTTPS, open SSL/TLS Status in cPanel and check that the domain has a valid certificate.
  • If the server’s own firewall may be blocking the CDN, ask your host. Give the time of the error and the CDN’s name.
  • Turn the CDN back on when you are done.

Fix a 502 from PHP, an app or a recent change

If the 502 began after an update, a new plugin or new code, start there. If nothing changed, PHP or the app behind the web server may have stopped.

  • Before you change files, open cPanel › Backup and download a home directory backup and a database backup.
  • On WordPress, rename the folder of the plugin you added or updated last in wp-content/plugins, for example plugin-name to plugin-name-off.
  • Load the site. If it works, update or replace that plugin before you turn it on again.
  • If the 502 stays, rename the folder back and try the next most recent change.
  • Not WordPress? Undo the last change to your code, or restore those files from a backup made before the 502 began.
  • If the 502 began after a PHP version change in cPanel’s MultiPHP Manager or Select PHP Version, switch back and test.
  • If only slow pages fail, such as imports or large reports, make them faster or run them as cron jobs.
  • If the site is an app, such as Node.js or Python, restart it and read its log.
  • If every PHP page fails and the logs show nothing, open a support ticket. Give the time of the error, the page and what you have tried.

HostUpIndia Web & cPanel Hosting

HostUpIndia Web & cPanel Hosting runs on LiteSpeed with NVMe storage, and each plan card lists its CPU and RAM, so you know what your site gets. Every plan includes cPanel for the steps above, terminal (SSH) access, free SSL and daily backups kept 30 days.

Plans start at ₹49 a month on 3-year billing. Prices exclude 18% GST. See Web & cPanel plans.

  • Moving from another host? The in-house team moves your site for you: free website migration.
  • Support tickets and email are received 24 hours a day, 7 days a week; WhatsApp is open for questions from 10 am to 7 pm IST, Monday to Saturday.
  • More help guides.