Whenever you visit a website, your browser communicates with a web server by sending a request. The server then processes this request and returns the necessary resources, accompanied by an HTTP header and an HTTP status code. Usually, you won't notice the HTTP status code unless there's an issue. Essentially, it's the server's way of letting you know that something went wrong, along with a code to help identify the problem.
A 502 Bad Gateway is an HTTP status that signifies a problem with communication between servers that handle the website requests. This error happens when one server gets a bad response from another server it’s trying to communicate with.
The 502 Bad Gateway error is most commonly caused by:
- Server Overload: The server might be handling too much traffic or running out of resources, causing it to crash.
- Browser Issues: Sometimes, your browser might be the problem. Outdated versions or a full cache can lead to this error.
- Firewall Blocks: Your firewall might mistakenly block certain websites, thinking they’re harmful.
Variations for 502 Bad Gateway error
A 502 error can occur across various devices and services, though the specific message displayed may vary. Here are some common variations of this HTTP status code:
- Simple: Temporary Error (502), 502 Error.
- Descriptive: HTTP Error 502 Bad Gateway, 502 Server Error, often accompanied by an explanation.
- Technical: 502 – Web server received an invalid response, HTTP 502, 502 Proxy Error.
- Overload: 502 Service Temporarily Overloaded.
- Server-specific: 502 Bad Gateway Nginx, depending on the server software.
- Blank screen: Some websites may display only a plain white screen.
Some website owners design custom error pages that provide extra information. For example, Chrome includes troubleshooting tips and recommends trying again.
Fixing 502 Bad Gateway error
Step 1: Reload the page
A 502 Bad Gateway Error is often temporary and may be caused by a sudden spike in traffic. Simply refreshing the page can usually fix the problem. On Windows, press F5 or CTRL + F5. On Mac, use CMD + R.
Step 2: Check site status
If the 502 error code persists, the website's server may be experiencing downtime.
There are several tools available to check if a site is down, such as Down for Everyone or Just Me. Just enter your URL to see the website's status. This way you can determine if the problem is on your end only.
Step 3: Clear browser cache
Corrupted cookies and an outdated cache in your browser can sometimes cause the error. Before making any changes to your WordPress site, it's important to determine whether your browser is the source of the problem by clearing its data history.
To clear browser data in Chrome, follow these steps:
- Open Chrome on your computer.
- Click on the three dots at the top right corner, then select Delete browsing data.
- Choose a time range, like Last hour or All time.
- Select Cookies and other site data and Cached images and files.
- Click Delete data.
Note that the steps to clear cache and cookies in other browsers, such as Safari, are generally similar, though the specific menus and options may vary slightly.
Step 4: Use incognito mode
You can try accessing the site in Incognito mode. If the 502 Bad Gateway error doesn't occur, the issue may be due to a browser extension.
To pinpoint the problematic extension, start by disabling them one at a time, and check if the website loads correctly after each one.
When the site loads without issues, you have found and removed the extension that was causing the blockage.
Step 5: Try another browser
You could try a different browser to make sure there are no browser related issues. If you’re using Google Chrome, for example, try using Microsoft Edge.
Step 6: Flush DNS cache
Another frequent cause of a 502 Bad Gateway error is DNS-related issues, such as incorrect IP addresses or unresponsive DNS servers.
In such cases, flushing your DNS cache might resolve the problem. Use this guide to flush the DNS cache. Also, if you recently pointed your domain, it might take up to 24 hours for DNS changes to propagate.
Step 7: Try another device
If the above 502 error solutions don’t resolve the issue, try testing the website on another computer or mobile device, preferably on a different network.
You can also restart your computer and router. This will help determine whether the error is due to your networking equipment or if the problem originates elsewhere.
Step 8: Check CDN setup
If you are using 10Web Cloudflare Enterprise CDN, make sure your DNS records are correctly configured to point to your server, avoiding any unintended redirects. For more details, check this guide.
Step 9: Check error logs
Review your website error logs to identify the details of the issue.
- On 10Web Dashboard, head to Hosting Services > Logs.
- Use the drop-down menu at the top of the page to choose Error.Log.
- Review the logs for any PHP Warning or PHP Notice errors.
- Locate the problematic plugin by following the path indicated by the error messages: wp-content/plugins/[plugin name].
- From the Plugins section, use the Deactivate option to turn off the plugin. This won’t delete your data.
Step 10: Restart the PHP
This action can refresh your server connections and potentially fix the error.
- Accessing 10Web Dashboard > Manage section of the website
- Navigate to Hosting Services > Tools
- Select Restart PHP to restart the PHP engine.
Step 11: Check plugins and themes
To check if a specific plugin or theme is causing the problem, you can temporarily deactivate them.
Case 1: If you have access to WordPress Dashboard
- Head to the Plugins section of your WordPress Dashboard.
- Choose all your plugins using the checkmark.
- Choose Deactivate from the dropdown menu of Bulk Actions.
- Click Apply.
- If the issue is solved, enable your plugins back one by one to find the exact plugin causing the issue.
Case 2: If you don’t have access to WordPress Dashboard
- Use SFTP to connect to your website files
- Double click on the web > wp-live folder to locate the plugins folder.
- Right-click on the folder and rename it.
- Try to access your website. If the error is resolved, it indicates that one or more of your active plugins are either corrupted or outdated.
- Rename the folder back to plugins and reactivate plugins one by one, reloading the site after each activation. When the error reappears, you’ve found the problematic plugin.
Important:
Run a security scan on your website, as persistent 502 errors could indicate that the website is hacked.
Conclusion
There are several steps you can take to troubleshoot and resolve a 502 gateway error on your site. Generally, this issue arises either from the server-side or third-party plugins and themes with poorly written code or unoptimized queries. For some cases, it can also be a client side issue connected with browser or network caches.