How to fix the 502 Bad Gateway Error

A 502 Bad Gateway error is a communication breakdown between servers that happens when one server acting as a gateway or proxy can’t get a proper response from the upstream server.
To fix it, you can refresh your browser, verify the website’s status, clear your cache, try incognito mode, reset your DNS settings, test from a different device, review server logs, disable plugins or themes, check your CDN settings, and adjust PHP timeout limits.
The thing is, this error affects everyone differently. Sometimes, it’s a quick glitch that goes away when you refresh. Other times, it signals a deeper server problem that needs troubleshooting. The good news is that many 502 errors have simple fixes you can try yourself.
We’ll walk you through each solution step by step, starting with the quickest fixes and moving toward more advanced troubleshooting. By the end, you’ll know exactly what to do the next time you see that 502 error message.
What does 502 Bad Gateway mean?
A 502 Bad Gateway error is an HTTP status code showing a communication problem between the two servers on the internet, where the proxy server or gateway server receives an invalid response from the upstream server. In most cases, resolving the 502 error is easy and quick.
What causes a 502 Bad Gateway error?
A 502 Bad Gateway error is caused by one server not being able to communicate properly with another server
What is the root cause of the 502 error? It can be server communication problems, network connectivity issues, overloaded servers, misconfigurations, or faulty applications that prevent proper data exchange between systems.
Here are the main causes and what they mean:
Cause | Description |
Server overload | The upstream server is receiving too many requests and can’t respond in time. |
Network connectivity issues | Problems with internet connections between servers, including timeouts or dropped connections. |
Server downtime | The upstream server is temporarily offline for maintenance or has crashed. |
Firewall restrictions | Security settings blocking communication between servers. |
DNS problems | Domain name resolution issues preventing servers from finding each other. |
Proxy/Gateway misconfiguration | Incorrect settings on the intermediate server handling requests. |
Application errors | Bugs or crashes in the web application code causing invalid responses. |
CDN issues | Problems with Content Delivery Network servers distributing your content. |
Database connection problems | The web server can’t connect to the database to retrieve information. |
PHP/Script timeouts | Scripts taking too long to execute and timing out before completion. |
The tricky part is that 502 errors can look the same to users even when they have completely different underlying causes. That’s why troubleshooting often involves testing multiple solutions to find what works.
How to fix the 502 Bad Gateway error
To fix the 502 Bad Gateway error, try each of these simple solutions one at a time. Most of these fixes take just a few minutes, and you’ll often solve the problem without needing technical expertise.
1. Refresh the page
A 502 Bad Gateway error is usually temporary, stemming from a sudden traffic surge. A quick refresh can resolve the issue.
On Windows, press F5 or CTRL + F5. On Mac, use CMD + R.
2. Check the site status
If the 502 error code is still showing, it is possible that the website’s server might be currently experiencing downtime.
Luckily, there are many tools to examine whether the site is down, including Down for Everyone or Just Me and IsItDown. Simply input the URL and check the website’s status.
3. Clear your browser cache
If the invalid response error persists, your browser cache may have saved outdated and corrupted files. Clearing the browser cache can offer a 502 Bad Gateway fix.
Keep in mind that removing cached files might result in losing important browser data, including bookmarks and settings preferences. To prevent this, export your data from the browser and import it back later.
4. Try in Incognito mode
Access the website in Incognito mode to determine whether the 502 gateway timeout appears due to a browser-related issue. To open an Incognito window, click on the three-dots button on your browser screen and choose New Incognito Window.
If the error doesn’t occur in Incognito mode, your browser extension is likely causing the problem.
Try to disable your add-ons or extensions one by one. When you delete the extension causing the error, you should be able to access the website. From our experience, an ad-blocker extension is usually the culprit.
If disabling browser extensions doesn’t help, try a different browser. For example, if you’re currently on Google Chrome, try using Mozilla Firefox.
If the page works on the new browser, your previous browser might be causing the error. To solve the problem, try deleting and reinstalling your faulty browser.
5. Flush the DNS cache
Other common causes of 502 Bad Gateway are DNS problems, such as incorrect IP addresses and unresponsive DNS servers.
In this case, flushing your DNS cache can be the answer. This method works similarly to clearing your browser’s cache. It will remove faulty files from your DNS server.
Consider also temporarily changing your DNS servers. Your ISP assigns your DNS servers by default. However, you can always change them to a third-party server, such as Google Public DNS.
6. Test on another device
If none of the above 502 error fixes work, test your internet connection on another computer or a mobile device, ideally connected to a different network.
Additionally, try restarting your computer and router. This will show whether the error is related to your networking equipment or if the problem lies elsewhere.
7. Check error logs
If you encounter a 502 error on a website after a change or an update, you might be dealing with a web server error. The best approach to solving this issue is to check your website error log.
Usually, your hosting service lets you access your website’s error log files through an admin dashboard. You can also enable error logging on your WordPress website by adding the following lines in wp-config.php:
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
All of the generated errors will appear in the wp-contents/debug.log file, allowing you to detect which ones are causing a 502 Bad Gateway error.
8. Check plugins and themes
Sometimes, faulty plugins or themes can cause the error.
This is because poorly coded plugins and themes can conflict with each other. When this happens, your server will stop every script and query on your website, making it inaccessible.
For some websites, the issue usually comes from caching or security plugins. There is a good chance that these plugins block communication between servers, causing the error to persist.
If you don’t have a caching or security plugin installed but still encounter the HTTP 502 error, it’s best to disable your plugins and re-activate them one by one. To do so, go to Plugins and click Deactivate from the Bulk Actions menu.
Then, activate each plugin while refreshing your WordPress site after each one. Once the 502 error pops up again, you will find the problem plugin.
However, if you can’t access your WordPress dashboard, you can try disabling them from your hosting panel or FTP program. Navigate to the wp-content directory and rename the plugins directory, for example, plugins-disable.
If you use Hostinger, access your hPanel and click on Files. From there, go to File Manager → public_html → wp-content.
Once your site starts working after all plugins are disabled, you may rename the folder back to plugins. Then, try enabling the plugins one by one to determine which one caused the error in the first place.
If the website still doesn’t work, follow the same steps with your WordPress themes.
9. Check your Content Delivery Network (CDN)
Issues with your content delivery network (CDN) or DDoS mitigation services can also cause 502 Bad Gateway errors.
A CDN adds an extra layer between your server and browser to deliver web content efficiently. However, this layer can run into an issue when connecting with your origin server, resulting in 502 Errors.
One notable example is Cloudflare, where the 502 Bad Gateway can occur in two different variations depending on the issue.
The screen above indicates that the issue is on Cloudflare’s side. To fix it, you’ll need to reach out to their customer support team. Remember to check the Cloudflare System Status page before doing so.
Alternatively, you can disable Cloudflare. However, keep in mind that your DNS propagation may take a couple of hours.
If you see the Cloudflare error shown above, it means that the issue is with your current web hosting provider. In this case, try contacting your web host support team for assistance.
10. Increase PHP max_execution_time and max_input_time
PHP timeout happens whenever a PHP process loads for more than the specified max_execution_time or max_input_time. These are the values set in your PHP configurations on your web server. Usually, the values are set to 300 seconds by default.
A timeout can happen during the migration process and trigger a 502 Bad Gateway error. To fix this issue, you can contact your hosting provider’s customer support to check what your values are set at and if you can increase them.
How to fix 502 Bad Gateway error – Video tutorial
If you prefer to follow along with a video tutorial, check out this Hostinger Academy guide on how to solve this generic error:
502 Bad Gateway error variations
A 502 error can appear on any device or service, but the exact message might differ. Here are some variations of this HTTP status code you might see:
- Simple – Temporary Error (502), 502 Error.
- Descriptive – HTTP Error 502 Bad Gateway, 502 Server Error, with 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 server software.
- Blank screen– some websites show a plain white screen.
Some website owners create unique error pages with additional information. For instance, Chrome offers troubleshooting tips and suggests retrying.
GitLab explains the communication issue and provides solutions.
X (previously Twitter), on the other hand, displays a friendly message with an illustration.
Improve your user experience with customized error pages
We recommend customizing your pages with error codes. This way, you can improve your user experience by providing helpful content for your visitors.
Is a 502 Bad Gateway permanent?
A 502 Bad Gateway error is usually not a permanent website failure. Most of these errors clear up on their own within minutes, or you can fix them quickly by refreshing the page, clearing your cache, or trying one of the other solutions we covered.
Does a 502 Bad Gateway error affect SEO?
While 502 errors are temporary, they can hurt your search engine rankings if they stick around too long.
Search engines like Google want to give users a good experience, so pages that are frequently inaccessible due to server errors can see their rankings drop. Learn more about the many factors that influence your rankings in our SEO guide.
The key is to act fast when you notice 502 errors on your site. Use the troubleshooting steps we outlined, starting with the simple fixes and working your way up to more technical solutions. Most of the time, you’ll solve the problem without needing to call in professional help.
Remember, 502 errors are frustrating, but they’re also fixable. Keep this guide handy for the next time you run into one, and you’ll know exactly what to do.
All of the tutorial content on this website is subject to Hostinger's rigorous editorial standards and values.