Hostcano Blogs

A Helpful Guide to Solve and Fix the 502 Bad Gateway Error

Guide to Solve and Fix the 502 Bad Gateway Error

Websites can make it difficult and frustrating to navigate. Two examples are the white screen of death and the terrifying error when connecting to a database. The 502 bad gateway error is a more common one. Why? It happens all over the web, not just to WordPress sites but also to popular services like Gmail, Twitter, and Cloudflare. We don’t care much about how this impacts your WordPress website.

There are many reasons 502 errors could occur, from browser issues to problems with CDNs. This article will discuss the troubleshooting steps you should take when a 502 Bad Gateway error occurs on both the client-side and server side.

What, in a Nutshell, is a 502 Bad Gateway Error?

The 502 Bad Gateway errors indicate that the server received an incorrect response from an outbound server.

Your browser sends a request every time you visit a website — the request is processed by the web server, which then returns the requested resources with an HTTP header. Unless something goes wrong, an HTTP status code is not usually visible. The server’s telling you about an error and the code to fix it.

There are many types of 500 status errors codes, including 502, 503, 504, 504, 508, 520 and 503, 504, 504, 504, 504, 504, 508, 508, 508, 508, 508, 508, etc. Each code has a slightly different meaning. It indicates that the request was accepted but not fulfilled by the server.

An HTTP status code beginning with the number “5” refers to errors due to a communication or network problem between web servers.

502 Bad Gateway

Other status codes that 5xx include 500 Internal Server Error (501 Not Implemented), 503 Service Unavailable (503 Service Unavailable), 504 Gateway Timeout (504), and 504 Gateway Timeout (501 Not Implemented). Although the exact causes of each error may vary, most likely, the problem lies within the server.

What causes a 502 bad gateway error?

Before you can fix Gateway, you must first examine the possible causes of the error.

Unresolved domain names If a domain name does not resolve to the correct IP, this is called an unresolved domain name. Remember that DNS server changes can take up to 24 hours for a domain name to become active after moving to another host.

When an origin server runs out of resources, it can crash and become overloaded, leading to an HTTP error 502. Server overload is due to sudden surges in traffic, low memory, and software timeouts.

Browser errors

Sometimes, a browser may display a 502 error code despite having no network or server problems. This error could be because of browser extensions incompatible with your browser, such as ad blockers or outdated browser versions—problems with home-network equipment. There is a chance your network equipment may be experiencing temporary connectivity issues if you see HTTP 502 errors in more than one browser or website.

Firewalls. Firewalls protect your website against suspicious traffic. Some firewall systems can detect false positives because they are too sensitive. It could be blocking a particular ISP or a request to a CDN.

How do I fix 502 bad Gateway Errors?

Server-side issues usually cause the 502 Bad Gateway errors, but they could also be caused temporarily by misconfigurations on the client side. We’ll discuss common problems with both the server-side and client-side causes.

Some solutions are specific to WordPress, but most are to other websites.

Refresh the Page

The first is simple: wait for a few minutes and then refresh the page. A sudden surge in traffic can cause errors.

A simple page refresh will usually suffice. Windows users can use F5 or CTRL+ F5, while Mac users may press CMD+ R.

Online tools such as Website Planet and Host Tracker can check if the website has gone offline. It will identify if the problem is server-side or client-side.

Clear Browser Cache

If the error persists, you may have a browser cache that has stored corrupted or outdated files. Clearing the browser cache may be able to fix the HTTP 502 Bad Gateway error.

Clear cached files could cause you to lose essential browser data such as bookmarks or setting preferences. You can prevent this by exporting your browser data and importing it back.

In Incognito Mode

It is also a good idea to access the website in Incognito mode. It allows you to determine if the HTTP Error 5002 message is due to a browser-related problem. Click on the three dots button on your browser screen to open an Incognito Window.

Hostcano in Incognito mode

A browser extension might be responsible if the error does not occur in Incognito mode.

Keep this in mind as you disable add-ons and extensions slowly. After you have deleted the one that caused the error, you can access the website.

Try opening a new browser session if disabling extensions does not work. Mozilla Firefox is an alternative to Google Chrome.

 

Your previous browser could be why the page does not generally load in the new browser. You can fix the problem by uninstalling and reinstalling your browser.

Flush DNS Servers

This error can be due to DNS issues, such as unresponsive servers or incorrect IP addresses.

It is where flushing your DNS cache could be the solution. It works in the same way as clearing your browser’s cache. It will delete any faulty files from the DNS server.

Another option is to change your DNS servers temporarily. Your ISP assigns your DNS servers by default. You can change the DNS server to another third-party provider, such as Google Public DNS.

Try it on another Device

If none of these solutions fix the HTTP error 502, try connecting to another computer or mobile device.

Restart your computer and other network equipment. Turn off your computer and unplug the wireless router. Let it cool down for a while before plugging back in.

It allows you to determine if the problem is due to your network equipment or elsewhere.

Check Error Log

If you get an error message after making a change or updating, it could be due to your server. It gets solved by checking your website error log.

Your hosting service usually gives you access to enable website error logs through an administrator dashboard. Lines add to wp-config.php to enable error logging for your WordPress site:

Error-Log-Check

All 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.

Search for Plugins and Themes

Sometimes, the problem can be because of faulty themes or plugins.

Because plugins and themes that are poorly coded can cause conflicts with one another. It will cause your server to stop all scripts and queries on your website, rendering it inaccessible.

Some websites experience issues with security plugins or caching. These plugins could block communication between servers and cause the error to persist.

If you do not have a security or caching plugin installed and still get an HTTP 502 error, it is best to disable all plugins and then reactivate each one one at a time. Go to Plugins, then click on Deactivate in the Bulk Actions menu.

Next, activate each plugin and refresh your WordPress site after each one. You have successfully identified the problem plugin by displaying the 502 Error again.

disable-plugin

If you cannot access your WordPress dashboard from your hosting panel, or an FTP program, you can disable them. Navigate to the directory wp-content and rename the plugins directory, such as plugins-disable.

Access your cPanel to access Hostcano and click Files. Go to File Manager-> public_html-> wp-content.

cPanel hosting

After your site is working again, after you have disabled all plugins, you can rename the folder to plugins. Next, enable each plugin one at a time to identify which one is causing the problem.

If your website is still not working, you can follow the same steps with your WordPress themes.

Checking Up the CDNs

The 502 Bad Gateway error can also exist caused by problems with your CDN and DDoS mitigation services.

A content delivery network is an additional layer between your browser and server to deliver web content efficiently. This layer can cause 502 errors if not connected to your origin server.

Cloudflare is a notable example. The 502 Bad Gateway can appear in two variations depending on the issue.

The screen below indicates that Cloudflare is responsible for the problem. You will need to contact their customer service team to fix the problem. Before you do this, make sure to visit the Cloudflare System Status Page.

You can also disable Cloudflare. However, DNS propagation could take several hours.

Error-502

If you get the Cloudflare error, your current hosting provider is likely the problem. If this happens, contact your web host support team to get assistance.

Check out the site status

The origin server may be experiencing downtime if the 502 error code persists despite having tried all the methods.

Several online tools can help you determine if your site is down. These include Down For Everyone or Just MeIsItDown. Enter your URL to check the status of your website.

PHP max_execution_time, max_input_time

PHP timeout occurs when a PHP process loads faster than the max_execution_time and max_input_time. These values are in the PHP configurations of your web server, usually set to 300 seconds by default.

A timeout could occur during the migration and cause a 502 Bad Gateway error. Talk to your web host to determine your values and whether you can adjust them.

Search CDNs

The 502 Bad Gateway error can be due to problems with your CDN and DDoS mitigation services.

A content delivery network is an additional layer between your browser and server to deliver web content efficiently. 

This layer can cause 502 errors not connected to your origin server.

Cloudflare is a notable example. The 502 Bad Gateway can appear in two variations depending on the issue.

The screen below indicates that Cloudflare is responsible for the problem. You will need to contact their customer service team to fix the problem. Before you do this, make sure to visit the Cloudflare System Status Page.

You can also disable Cloudflare. However, DNS propagation could take several hours.

If you get the Cloudflare error, your current hosting provider is likely the problem. If this happens, contact your web host support team to get assistance.

Contact Customer Support

You can contact the customer service team if none of these solutions work.

Try to describe the problem and include any troubleshooting steps taken. Give as much detail as possible and allow the support team to assist.

502 Bad Gateway Error Variations

This error is on every browser, operating system, or service. It can appear in many different ways. These are some alternative options that you may find on the internet:

  • Temporary Error (502)
  • 502 Error
  • Error 502
  • HTTP Error 502 Bad Gateway
  • 502 Server Error – The server encountered a temporary problem and was unable to complete your request
  • 502 – A gateway or proxy server is an error to the Web server.
  • HTTP 502
  • 502 Proxy Error
  • Bad 502 Gateway
  • 502 Service Temporarily overloaded
  • 502 Bad Gateway Nginx
  • Blank white screen

Remember that not all websites and services offer the same 502 Error pages. They may look completely different.

Google chrome error 502

Chrome’s 502 Bad Gateway error screen informs you that Chrome encountered a temporary problem and was unable to complete your request. Chrome suggests that you try it again within 30 seconds. Try accessing the site using a different browser window if the problem persists.

Final Wrap-Up

If a server acting as a gateway receives a wrong response from an origin server, a 502 Bad Gateway is a problem. This error can impact your conversion rate, user experience, page rankings, and other factors.

The server side is usually the source of the problem, as indicated by the status code. 

The problem is not due to your website, internet connection, or computer. It is essential to be on the lookout for broken plugins and themes.

These troubleshooting steps should help you eliminate any errors and get your site back to being stable. We would love to hear your suggestions and solutions.

Facebook
Twitter
Reddit
LinkedIn
Pinterest

Related Posts

Newsletter

Leave a Reply