502 Bad Gateway errors

If your website shows 502 Bad Gateway with openresty underneath, the server in front of your website couldn’t get a response from the web server behind it. Most of the time, this is a temporary server problem that clears up by itself within a few minutes. Sometimes it’s caused by a specific script on your website.

This article explains what the error means, how to tell which kind of 502 error you’re seeing, and what you can do about it.

What a 502 error means

A 502 error means the web server that runs your website couldn’t handle the request.

This can happen for a variety of reasons. A few common reasons include:

  • The server being overwhelmed, for example due to a flood of traffic to the server.
  • Maintenance or updates on the server.
  • A PHP script timing out, or crashing in some ways.

Check that it’s really a 502 error

Before going further, check the exact error message. Several errors look similar but have different causes:

Figure out which kind of 502 error you have

Ask yourself two questions:

  1. Does the error appear on random pages, or only when you do something specific? For example, submitting a certain form, running an import or saving settings in your admin area.
  2. Does the error appear right away, or only after the page has been loading for a minute or two?

The answers point to one of the situations below.

Random 502 errors on any page

This usually looks like this:

  • The error appears on different pages, seemingly at random.
  • The error appears almost immediately.
  • Reloading the page works, or the site comes back after a few minutes.
  • Static files, such as images or plain HTML files, are affected too.
  • Other websites on the same account, or other InfinityFree websites, are down at the same time.

This is a server-side problem, and it’s not caused by your website. Changing your code, clearing caches or reinstalling WordPress won’t help.

  1. Wait a few minutes, then reload the page.
  2. Check the InfinityFree status page for larger outages.

502 errors on a specific page or action

This usually looks like this:

  • The same page or action fails every time, while the rest of your website works fine.
  • The error often only appears after the page has been loading for a minute or two.

This points to the script behind that page or action. A script that takes very long to finish, or gets stuck waiting for something, can end in a 502 error.

  1. Think about what changed recently. If you installed or updated a plugin, theme or script just before the errors started, try disabling it.
  2. If the action processes a lot of data at once, such as a large import, export or report, try splitting it into smaller batches.
  3. Enable error display to see if the script also triggers PHP errors. See our article about HTTP 500 errors for how to do this.

502 errors that don’t go away

If your website shows a 502 error on every page for more than an hour, including static files, check the status page first. If nothing is reported there, ask for help on the forum.

Short, intermittent 502 errors are very hard to investigate, because they’re usually over before anyone can look into them. If the error comes and goes, waiting is usually the only option.

1 Like

Maybe worth adding a link to the status page right in the first steps, since that’s usually the first thing people should check.

That would be the ideal scenario, but getting those 502 errors on the status page is not so simple.

I don’t get notices of system issues from iFastNet proactively, and the errors that do come up quickly are from my own, external monitoring catching that things are down. But the monitoring cannot detect the 502 errors yet.

So right now, any status page issue about 502 errors has to be written by me, by hand, after I am sure that there is a problem, which relies on reports to the forum. And that’s usually too late.

Thanks for explaining the constraint — that makes a lot of sense.

One idea that might help: if the current monitoring checks static files or basic pings, those can still return 200 even while PHP is throwing 502s. A synthetic check that requests an actual PHP endpoint and alerts specifically on a 502 (or any non-2xx) response code might be able to catch these automatically, so the status page could update without waiting for forum reports.

Even a simple external uptime check that matches on the HTTP status code could work as a start. Just a thought — thanks again for the detailed reply!