What Is 502 Bad Gateway and How to Solve It

502 bad gateway
502 bad gateway

Sometimes when you are browsing and opening a website, you experience the 502 Bad Gateway error. One of the most common types of website errors that you will see is the HTTP 502 Bad Gateway Error.

This is a type of error that not only occurs on WordPress websites, but sometimes also occurs on Gmail, Twitter, and Cloudflare.


In simple terms, this is a condition where both web managers and web users are faced with a blank condition so that the website can no longer be operated. Likewise, people who want to access the web or blog, will be constrained because the condition of the blog only has the words 502 bad gateway.


If you experience 502 bad gateway, don’t panic and despair. This condition is indeed annoying, especially if the website you manage is very influential for the existence of your business.

If you are faced with this problem, there are several steps you can take to solve it. But before stepping on the discussion of how to solve it, it’s a great idea to find out what and the cause. Now for more details, please follow the full discussion below.


What Is 502 Bad Gateway Error

Every time you visit a website, your browser will send a request to the web server. The web server will receive and process the request, then the web server will send back the requested resource along with an HTTP header and HTTP status code.


Usually, the HTTP status code is not visible unless something is wrong. The HTTP status code serves as a notification if something goes wrong. The numbers shown are the codes that can help you to find the solution.


One of the most frequently seen types of error codes is the 500 status error codes (500, 501, 502, 503, 504, etc.). Each number has a different meaning. These codes indicate that your request has been terminated, but the server does not allow the request to be processed. 502 Bad Gateway is an error that indicates that the server that functions as a gateway or proxy, received an invalid response from the inbound server.


Several kinds of 502 errors according to the notification that appears:

  1. Error 502
  2. HTTP 502
  3. That’s an error
  4. Error 502 Bad Gateway
  5. Error 502 Service Temporarily Overloaded
  6. 502 Server Error: The server encountered a temporary error and could not complete your request
  7. 502 Proxy Error
  8. HTTP Error 502 – Bad Gateway
  9. Temporary Error (502)
  10. 502 Bad Gateway Nginx


How to Solve 502 Bad Gateway

The following below are some methods that you can use to resolve error 502, as follows:

  1. Refresh Website Page

The first step you need to do when you experience error 502 is to load or refresh the website page.

Press the F5 key on the keyboard of your laptop device, then wait a while. The error could be caused by an overloaded server. You can check again by accessing the website via another browser or a private browser.

In addition, you can also check at downforeveryoneofjustme.com. This website will notify you if your website is down or the problem is on the client side.


  1. Clear Browser Cache

If the first method doesn’t work, then clearing the browser cache can be an effective next step. Cache is a file that is stored on the server because you open the web for the umpteenth time. So the cache automatically makes it easier for you to receive a complete web view without the need to make the server work over and over again.

Although useful, cache can also make your website overloaded or overloaded. Therefore, clearing the cache will help the web relieve files, and the 502 bad gateway problem has a chance to be resolved quickly.


  1. Problem with DNS

The 502 bad gateway error can also occur due to DNS issues, for example the domain does not resolve the correct IP. If you recently migrated your WordPress website to a new hosting, you will need to wait at least 24 hours to make sure that the migration goes smoothly.

This depends on the TTL value of your DNS. You can also try clearing your local DNS cache. The way it works is similar to browser cache.


On Windows, you just need to open a command prompt and enter the following code: “ipconfig /flushdns”.

If successful, you will get a “successfully flushed the DNS resolver cache” message.


For Mac users, you can enter the following code into your Mac terminal: “dscacheutil – flushcache”. For Mac users, you won’t see any message after that.

Finally, you can change your DNS server temporarily. By default, the DNS server will be automatically selected by your ISP or internet provider. But you can temporarily change its DNS server to a public DNS server.


  1. Deactivate plugin

All of your WordPress plugins are PHP scripts, so the first thing you should do is deactivate the WordPress plugin.

Since you cannot login to the WordPress dashboard due to a 502 error, you will need to connect to your website via FTP Client or File Manager in cPanel.

Once you are connected, click into the /wp-content/ folder and rename the plugins folder to old-plugins.


After that, create a new folder and name it plugins. Now you need to visit the WordPress website to see if this solves this error problem. If this solves the problem, it means this plugin is causing your website error.

By following the steps above, you have deactivated all of your WordPress plugins. To determine which plugin is causing the problem, you will need to go back to the FTP client or File Manager in cPanel.

Then, select the /wp-content/ folder and delete the empty plugin folder. After that, you need to rename the plugin-old folder to plugins. That way, you will return all the plugins to your WordPress website.


However, this plugin will remain inactive. Log in to your WordPress admin area and select the plugin page. You can then activate your plugins one by one and visit different pages on your website after activating each plugin. Keep doing that until you find the plugin that is causing the 502 bad gateway error.

wordpress themes
wordpress themes
  1. Using the Default WordPress Theme

If disabling the plugin doesn’t solve the problem, then the next step is to change your website’s theme to the default WordPress theme.

This will deactivate your current WordPress theme. First, you need to connect to your WordPress site using an FTP client or File Manager in cPanel. Once connected, go to /wp-content/themes/ folder.

Find your current WordPress theme and download it to your computer as a backup. After downloading your theme, you can go ahead and remove it from your site


Well, if you already have a default theme like Twenty Twenty One or Twenty Twenty installed, then the theme will be automatically activated. If not, then you need to first install one of the default WordPress themes. Check your website carefully to make sure that the 502 error is resolved.


  1. Check the Error Log

If the 502 bad gateway error appears on the website after you make certain changes, then it’s most likely that the change caused the 502 bad gateway error. Looking at the error log is one way to find out.


To enable error logs in WordPress, you simply add a few lines below to wp-config.

define( ‘WP_DEBUG’, true );

define( ‘WP_DEBUG_LOG’, true );

define( ‘WP_DEBUG_DISPLAY’, false );


To see the entry changes that occurred, you can access the wp-contents/debug.log file to analyze the errors that occurred.


  1. Troubleshooting

Problems with web hosting are one of the reasons why error 502 occurs, generally shared by shared hosting users where there will be a script that will stop requests from querying websites.


This is done in order to prevent the occurrence of a server down and impact on other users with the same server.

If this error is due to a problem with the web hosting you are using, it is recommended to switch to VPS hosting.


Resolving 502 bad gateway error is not too difficult by trying the step guide above, you can also consult with your web hosting provider. Hopefully this article is useful.

1 thought on “What Is 502 Bad Gateway and How to Solve It”

Leave a Comment