Tutorial Fix 502 Bad Gateway Error On Nginx

Tutorial Fix 502 Bad Gateway Error On Nginx

A 502 bad gateway error is one of the most HTTP status codes that are like short notes from a server. When you visit a website, the browser sends a request to the webserver to send back the request resources. Once you face a 502 error, it means that the server has received an invalid response from an inbound server. According to the kind of browser, operating system, and web server, the 502 Bad Gateway error could appear with various names. This article presents Tutorial Fix 502 Bad Gateway Error on Nginx. Choose what you need among the available packages of Eldernode and purchase your own Linux VPS Server.

All about 502 Bad Gateway Error

Generally, the error messages that begin with ”5” mean the server can not perform the request. As you read above, a 502 Bad Gateway is a problem with the network/server. It indicates the server was not able to get a valid or any response from the origin server. Also, you may see 500, 503, 0r 504 error messages. Users of WordPress, Gmail, Twitter, and Cloudflare may view this error regularly. A 502 Bad Gateway is a generic error. So, you can not actually know your website’s exact issue and it just serves as an error web page to your visitors as shown below.


502 Bad Gateway Error

Recommended Article: Initial server set up on Ubuntu 20.04 LTS

What are the main reasons for 502 Bad Gateway Error

At the first sight, when you experience a 502 Bad Gateway Error, you do not know what exactly happened or why. To solve this error, it is a good idea to know the main culprits. Here are some of the reasons for 502 Bad Gateway responses:

1- Domain name not resolvable

2- Origin server down

3- DNS changes

4- PHP-FPM is not running

5- The server failure

6- Website overload

7- Faulty PHP programming

5- NGINX can’t communicate with PHP-FPM

9- Browser error

10- Firewall blocks request

11- PHP-FPM is timing out

12- Communication error

Most often, a 502 bad gateway error has nothing to do with you as a visitor to the site. But As a developer or owner of the website, first of all, check your FQDN is resolving correctly by using your DNS test tool or not. Also, your server should be reachable by using a ping test or traceroute. If all is ok, check your firewall log especially if you see unusual drops.

Note: Cloudflare users need to disable it since once they reach a certain limit, Cloudflare will return a 502 Bad Gateway error to your visitors.

If you are eager to see more details of any one of the above errors, go to your web server’s error log file. Since all error and diagnostic information is stored in this file, you can use it as a valuable resource. So, locate this file in Apache by going to /var/log/apache2/error.log and in Nginx by going to /var/log/nginx/error.log.

How to Fix 502 Bad Gateway Error on Nginx

In this section, review the ways you need to check to be able to solve the 502 Bad Gateway Error on Nginx. This error occurs because of server-side problems, misconfiguration, or issues from the client-side. Let’s see the steps to fix the 502 Bad Gateway Error on Nginx.

Refresh the page

If it is your lucky day, it should be solved just by clicking the refresh button after waiting around one or two minutes. Sometimes the best way is the simplest! So, why you do not try it? If the error is temporary, this will be the solution. You know the shortcuts, if not, press F5 or CTRL+F5 while you are working with windows. Also, if you are a Mac user, press Command+R. Even you can clear your browser cache and then refresh it again. It does not make changes? Do not worry and dive into the following solutions.

Use a new Browser

To make sure that the 502 error is not due to a browser-related problem, try a different browser. If you started a new browser session and loaded the site on a different browser and the error did not disappear, go for the next options.

Check your DNS server

As you read above, one of the reasons for the 502 bad gateway error could be DNS issues. If you have recently changed host servers or moved your website to a different IP address, you need to consider this option. So, you can flush DNS to troubleshoot this case. The DNS changes take full effect, which can take a few hours and your website will not be up and running till the end of the changes.

Change your Device

It is an easy solution to test the connection on another computer or a mobile device. If you can, try to connect to a different network too to make sure that the issue is about your machine or not.

Check Error Log

If you have recently made any change or update, it could be the reason for the 502 bad gateway error. Since the server log provides the details, check your error log to verify the server’s health.

Recommended Article: How to install Drupal on CentOS 8

Check for server connectivity issues

Your website will also serve visitors a 502 Bad Gateway Error page if your server is down for maintenance or any other reason. So, wait for your server to finish maintenance or fix the problem causing the error.

Check plugins and Themes

Since the misconfigured caching Plugins can often generate the 502 bad gateway error, check your plugins, themes, and extensions. So, you can simply deactivate all your plugins without losing any data.

Check for Firewall Configurations

As you know, your firewall is the gatekeeper of your website to protect your site from malicious visitors or distributed denial-of-service (DDoS) attacks. So, check and fix the faulty firewall configuration to not be the cause of this error.

Check CDNs

Content Delivery Network is also another cause of the 502 bad gateway error. So, if you are using a 3rd-party CDN provider, try to disable your CDN temporarily.

Check the site

If you are still facing the 502 error, it could be a good idea to check if other people have the same problem or not. So, use a tool to examine if your website is down. Input your URL and check the status of your website.

PHP Timeout

If a single PHP process runs longer than it should, you will also see an error 502 bad gateway. Since the max_execution_time (max_input_time) is in your PHP configurations on your web server, contact your web host to know about the values.

Contact your host

Finally, at this point, if you have not to get rid of this error, stop checking any other parameter and contact the customer support team. Remember to explain the above 11 steps of troubleshooting you tried.

If the recent 11 steps did not work, it means that the problem is not about your website, so te the host team will be able to solve the main issue.


In this article, you learned How to Fix 502 Bad Gateway Error On Nginx. Most of the time, the error will be eliminated after checking the first steps of this guide. But if you really could not solve it till the end, contacting the website administrator or your internet service provider is your latest solution.

How useful was this post?

Click on a star to rate it!

Average rating 1 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

View More Posts
Marilyn Bisson
Content Writer
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

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

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way


7 days a week, 24 hours a day