Select Page

“502 connection failed” and other 502 errors explained – and resolved

Web servers show 502 errors when they are unable to display a requested page – due to network error, security restrictions, and so on.

502 Connection failed is one such error reported by Fiddler, a web app debugging tool.

It means that Fiddler’s request for a web page was blocked (or request delayed) by the site’s web server or firewall or load balancer, causing the request to timeout.

There could be other reasons also for this issue.

Here at Bobcares, we help website owners resolve server errors as part of our Outsourced Technical Support services.

Today we’ll go through the top causes for 502 class errors, and how to fix them.

 

Causes and Fixes for 502 errors

These days, many computer networks use an intermediary server called “Proxy” to provide anonymous website access, bypass server firewall etc.

Users see 502 errors mainly when there is a connection problem between the Proxy server and the website server.

There are many variants of this error and the exact error message often read as :

  • Error 502 connection failed
  • 502 Bad Gateway
  • 502 Server Error: The server encountered a temporary error and could not complete your request

Though the error message differs, the reasons for 502 errors are common.

Let’s have a closer look at the various reasons for the error.

 

1. DNS issues

Domains often need changes in DNS during server migration, hosting provider switch etc. These dns changes are not instant and need few hours to propagate in the internet.

At this time of dns propagation, when a visitor access a website, browser will not be able to find the correct server IP and connection eventually times out. And it will show the “502 connection failed” error.

Similarly, websites for which DNS is handled by providers like Cloudflare often show this “502 connection failed” error message.

 

502 connection failed cloudflare error

 

This happens when the Cloudflare server is unable to get a proper response from the original web server having website contents. The major reasons for the error include :

  1. Wrong IP address set for the domain in Cloudflare portal.
  2. Cloudflare server not able to connect due to server firewall.

To fix the 502 connection failed error, our Hosting Support Engineers make sure that domain points to the correct server IP. This require DNS corrections for the domain at the Cloudflare portal too. Also, to eliminate the error, we see that the web hosting server firewall allows Cloudflare IP addresses.

2. Service status

We often see that the underlying cause for 502 errors can be service failures for web server, mysql server etc.

Let us see how these services affect the working of websites.

Our server seems to be offline again. I’m seeing 502 Bad Gateway error. Can you investigate and advise on the cause?

That was a recent support request that we received from a VPS server owner.

On a detailed investigation, our Engineers found that Mysql service on the server was failing. And the web server was not able to communicate to the website database which resulted in a 502 error.

Here, the parameter “Max Open Files” for Mysql was not enough for the MySQL service to handle database queries.

We increased the value of “Max Open Files” and reconfigured MySQL. That fixed the problem and websites became functional again.

Also, we largely see 502 errors when Web server in failed status. A simple restart of the httpd service will make the websites working again. To avoid recurrence, our Hosting Support Specialists goes way further and fixes the real reason for web server failure.

 

3. Firewall restrictions

Most Web Hosting servers have built-in firewall to block traffic from bad networks. Additionally, some servers implement Country based firewall block as well. That is, websites will be served only to users from selected countries.

In such cases, a user accessing the website from a blocked network will see 502 errors.

Here, our Server Security Specialists modify the server firewall in a way that it does not create a security risk for the server.

Nowadays, many website owners rely on third-party content delivery networks for faster loading of images, videos etc. on the websites.

So this firewall modification also need to accommodate these third-party content delivery networks as well.

 

4. Server connectivity

Similarly 502 errors can also occur due to connectivity issues from the user’s computer to the web server network.

A connection may not reach the server due to :

  1. Firewall on user’s computer
  2. Network restrictions by the internet service provider used

Hence, it is required to verify that the connection actually reaches the server network. If a simple telnet command to web server port works correctly, it means zero connection issues.

The exact command to check this from user’s computer is

telnet domain.com 80

When there are problems due to bad connectivity, disabling the antivirus program on the computer, debugging network connectivity with internet service providers etc. help to solve the 502 errors.

Conclusion

502 connection failed” error happens mainly when the Web server gives a weird response to a browser request via proxy server. Today we’ve seen the top reasons that cause this error and how our Dedicated Support Engineers fix them.


PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

SEE SERVER ADMIN PLANS

Submit a Comment

Your email address will not be published. Required fields are marked *

Bobcares
Bobcares is a server management company that helps businesses deliver uninterrupted and secure online services. Our engineers manage close to 51,500 servers that include virtualized servers, cloud infrastructure, physical server clusters, and more.
MORE ABOUT BOBCARES