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:
- 500 Internal Server Error usually means your PHP code crashed or your .htaccess file contains an invalid rule. See these articles instead: HTTP ERROR 500: fixing PHP errors on your website and Fixing .htaccess errors ("Something Went Wrong!")
- 502 Bad Gateway is the error covered in this article.
Figure out which kind of 502 error you have
Ask yourself two questions:
- 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.
- 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.
- Wait a few minutes, then reload the page.
- 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.
- Think about what changed recently. If you installed or updated a plugin, theme or script just before the errors started, try disabling it.
- If the action processes a lot of data at once, such as a large import, export or report, try splitting it into smaller batches.
- 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.