When information technology comes to WordPress, there are a lot of different errors that tin can exist downright frustrating and confusing. A few that come to heed are the white screen of death or the frightening error establishing a database connexion. But an even more popular 1 is the 502 bad gateway error. Why? Because this regularly happens around the entire spider web, not only to WordPress sites, simply even pop services such every bit Gmail, Twitter, and Cloudflare. But of course, we really only care about how it impacts your WordPress site. Read more below about what causes this error and some solutions on how to rapidly resolve it.

  • What Is a 502 Bad Gateway Error?
  • How to Fix the 502 Bad Gateway Error

What is a 502 Bad Gateway Error?

The 502 Bad Gateway mistake specifically means that the server received an invalid response from an inbound server.

The Internet Applied science Task Force (IETF) defines the 502 Bad Gateway error as:

The 502 (Bad Gateway) status code indicates that the server, while acting every bit a gateway or proxy, received an invalid response from an entering server information technology accessed while attempting to fulfill the request.

Every fourth dimension y'all visit a website your browser sends a request to a web server. The web server receives and processes the request, and then sends dorsum the requested resources along with an HTTP header and HTTP condition code. Typically an HTTP status lawmaking isn't seen unless something goes wrong. Information technology's basically the servers way of notifying you that something has gone wrong, along with the code on how to diagnose it.

There are many unlike types of 500 status fault codes (500, 501, 502, 503, 504, 508, 520, etc.) which all have slightly different meanings. These indicate that the request was accustomed, only the server prevented the fulfillment of the request.

502 bad gateway error in Chrome
502 bad gateway fault in Chrome

502 Bad Gateway Error Variations

Due to the various browsers, web servers, and operating systems, a 502 bad gateway fault tin present itself in a number of different ways. But they all accept the same significant. Below are simply a couple of the many unlike variations you might see on the web:

  • "502 Bad Gateway"
  • "Error 502"
  • "HTTP Mistake 502 – Bad Gateway"
  • "502 Service Temporarily Overloaded"
  • "502 Proxy Fault"
  • A bare white screen
  • "502 Server Error: The server encountered a temporary error and could not complete your request"
  • "HTTP 502"
  • Temporary Mistake (502)
  • 502. That's an error
  • 502 bad gateway Cloudflare
  • Bad Gateway: The proxy server received an invalid response from an upstream server

Some other variation you might see is a "502 server error."

502 server error in Chrome
502 server error in Chrome

And here is however another variation. "502 – Web server received an invalid response while interim equally a gateway or proxy server. In that location is a trouble with the page you are looking for, and information technology cannot be displayed. When the Spider web server (while interim as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server."

502- web server received an invalid response
502- web server received an invalid response

Other services such equally Twitter might even bear witness a completely different message for a 502 Bad Gateway error, such as "Twitter is over capacity." This definitely looks a little more user-friendly.

Twitter is over capacity
Twitter is over capacity (Img src: Softpedia)

And hither is a snapshot of how Google displays it. "502. That'due south an fault. The server encountered a temporary error and could not complete your request. Delight try once more in 30 seconds. That's all we know."

Google 502 error
Google 502 error

502 Errors Impact on SEO

Unlike 503 errors, which are used for WordPress maintenance mode and tell Google to check dorsum at a afterwards time, a 502 error can have a negative impact on SEO if not fixed right away. If your site is only down for say x minutes and information technology'south being crawled consistently a lot of times the crawler will simply become the page delivered from enshroud. Or Google might non even have a take a chance to re-crawl it before it's dorsum upwardly. In this scenario, you're completely fine.

Yet, if the site is downwards for an extended period of fourth dimension, say 6+ hours, then Google might see the 502 error equally a site level issue that needs to be addressed. This could bear upon your rankings. If you're worried virtually echo 502 errors you should figure out why they are happening to brainstorm with. Some of the solutions beneath can help.

How to Fix the 502 Bad Gateway Fault

A 502 bad gateway error is typically a trouble with the network/server, however, it can also be a client-side issue. And so we'll dive into a niggling of both. Bank check out these mutual causes and ways to prepare the 502 bad gateway error to and get support and running.

1. Effort Reloading the Page

One of the easiest and get-go things y'all should effort when encountering a 502 bad gateway fault is to simply await a infinitesimal or and then andreload the folio (F5 or Ctrl + F5). It could be that the host or server is simply overloaded and the site will come right back. While you're waiting, yous could also quickly effort a different browser to rule that out as an issue.

Another thing you can do is to paste the website into downforeveryoneorjustme.com. This website will tell you if the site is downward or if it's a problem on your side.

downforeveryoneorjustme
downforeveryoneorjustme

ii. Clear Your Browser Cache

Whenever y'all see issues like these it can exist good to clear your browser cache. Beneath are instructions on how to practise it in the various browsers:

Subscribe At present

  • How to Force Refresh a Unmarried Page for All Browsers
  • How to Clear Browser Cache for Google Chrome
  • How to Clear Browser Cache for Mozilla Firefox
  • How to Articulate Browser Enshroud for Safari
  • How to Clear Browser Cache for Internet Explorer
  • How to Clear Browser Enshroud for Microsoft Edge
  • How to Clear Browser Cache for Opera

iii. DNS Issue

A 502 gateway mistake could also be because of a DNS result, such equally the domain is not resolving to the correct IP, or the DNS server is non responding. If you have just migrated your WordPress site to a new host, is it important to await for things to fully propagate, which tin accept up to 24 hours in some cases. This depends upon the TTL value of your DNS records.

You can also effort flushing your local DNS enshroud. This is similar to clearing your browser cache.

In Windows simply open up Command Prompt and enter the following:

ipconfig /flushdns
Command prompt - flush DNS
Command prompt – affluent DNS

You should see a "Successfully flushed the DNS resolver Cache" if it worked.

For macOS users, you can enter the following in the terminal:

dscacheutil -flushcache

Notation: There is no success message on Macs.

And lastly, you could temporarily change your DNS servers. By default, DNS servers are automatically assigned by your Internet service provider. But you could try temporarily changing these to a public DNS server, such as Googles. In fact, some prefer to apply Google'southward public DNS long-term. If you have a premium DNS propagation usually is a lot faster.

four. Cheque With Your Host

The principal reason we typically see a 502 bad gateway error is due to an issue with the web host. Sometimes aquery, script, or request will accept too long and so it is canceled or killed past the server. A lot of hosts, especially shared hosts implement what they phone call a "kill script." Basically what this does is it volition end a request after a certain menstruum of time and then that it doesn't take a site down or impact other users. If you do a Twitter search for "bad gateway" you can run across thousands of tweets happening every day alerting their hosting company of the problem.

502 bad gateway tweets
502 bad gateway tweets

One reason you might want to consider moving to a host like Kinsta is that our platform runs in anisolated software container that contains all of the software resources required to run the site (Linux, NGINX, PHP, MySQL). This means that the software that runseach site is 100% private and is non shared, even between your own sites. This greatly reduces the chance of seeing a 502 bad gateway error. We aren't running aggressive kill scripts similar some shared hosts are. And even if 1 of your sites does happen to become down, it won't impact your other sites.

Another reason you could see a 502 gateway mistake with your host is likewise due to the fact that the server is simply not reachable, either because it is downwards or there is no connectivity. In this instance, information technology is recommended to check your WordPress host's condition page or open a support ticket.

5. Temporarily Disable CDN or Firewall

It could also be an effect with your content commitment network (CDN) or firewall. If you are using a 3rd-party CDN provider an easy style to troubleshoot this is to simply disable your CDN temporarily. For case, we are big fans of the free CDN enabler plugin. If yous are using that, you can just conciliate the plugin and and then test your site. Wp-admin not working? Simply log in to your site via SFTP and rename the plugin'due south folder to cdn-enabler_old. This will temporarily disable the CDN connection. The same goes for WP Rocket or any other plugin you might accept hooked up to your CDN.

Rename plugin folder temporarily
Rename plugin folder temporarily

This can also occur sometimes with providers that provide DDoS protection and mitigation or fully proxy services like Cloudflare, as they accept extra firewalls in-between. We have noticed that this happens once in a while on the Cloudflare free programme. Unfortunately, since Cloudflare is a fully proxy service, in that location is no quick way to simply disable it.

Still, before you lot go blaming Cloudflare, it is important to know that in that location are ii different types of 502 bad gateway errors variations with Cloudflare every bit seen below:

502 Bad Gateway at Cloudflare (Variation i)

If you see the following screen, this is actually a trouble on Cloudflare's end, in which case you should reach out to them for support. You can also check Cloudflare's status page to see if they're currently experiencing an outage.

502 bad gateway error
502 bad gateway error

502 Bad Gateway at Cloudflare (Variation two)

If you see the following screen, this is a problem with your host.

Cloudflare 502 bad gateway at host
Cloudflare 502 bad gateway at host

GoDaddy Firewall

Here is some other case with of an HTTP 502 error and GoDaddy's firewall. The issue is actually with the origin server (the hosting provider) due to a timeout, not the firewall itself.

HTTP 502 - GoDaddy Firewall
HTTP 502 – GoDaddy Firewall

6. Cheque Your Plugins and Themes

A lot of times the reason for scripts and queries being canceled by the server is due tobad code on your WordPress site, possibly from a tertiary party plugin or theme. We have as well seen a lot of misconfigured caching plugins generate 502 errors. A few ways you tin can troubleshoot this is by deactivating all your plugins. Remember, you lot won't lose whatever data if you simply deactivate a plugin.

If you can still access your admin, a quick mode to do this is to scan to "Plugins" and select "Conciliate" from the bulk deportment carte du jour. This will disable all of your plugins. If this fixes the result you'll demand to find the culprit. Start activating them one past one, reloading the site after each activation. When you run across the 502 gateway error render, yous've found the misbehaving plugin. You can then reach out to the plugin developer for help or post a support ticket in the WordPress repository.

Deactivate all plugins
Conciliate all plugins

If you can't admission your admin y'all can FTP into your server and rename your plugins binder to something like plugins_old. Then check your site once again. If it works, then you lot volition need to test each plugin ane past 1. Rename your plugin folder back to "plugins" so rename each plugin binder inside of if it, one past ane, until you lot notice it.

Rename plugin folder
Rename plugin folder

E'er makes sure your plugins, themes, and WordPress core are upward to date. And check to ensure you lot are running a supported version of PHP. You tin always reach out to your host for aid. We employ New Relic and other troubleshooting methods here at Kinsta to help clients narrow downward what plugin, query, or script might be causing the error. Yous tin can also use your own custom New Relic central.

Time consuming queries to database
Fourth dimension-consuming queries to the database

If it turns out to exist an efficient query or bad code in a plugin, you might need to bring in a WordPress developer to fix the result.

7. Check Logs

Yous should likewise have advantage of your error logs. If yous are a Kinsta client, you can easily meet errors in the log viewer in the MyKinsta dashboard. This tin can aid yous speedily narrow downwards the outcome, especially if information technology's resulting from a plugin on your site.

Check error logs for 502 bad gateway errors
Check error logs for 502 bad gateway errors

If your host doesn't have a logging tool, you can too add together the following code to your wp-config.php file to enable logging:

          define( 'WP_DEBUG', true ); ascertain( 'WP_DEBUG_LOG', true ); ascertain( 'WP_DEBUG_DISPLAY', false );        

If y'all need more assist on how to enable WordPress debugging mode here is a full step by footstep tutorial.

The logs are typically located in the /wp-content directory. Others, like here at Kinsta might have a defended folder called "logs".

wordpress error logs folder sftp

You can besides bank check the log files in Apache and NGINX, which are commonly located here:

  • Apache: /var/log/apache2/error.log
  • NGINX: /var/log/nginx/error.log

If you are a Kinsta customer y'all can also take reward of our analytics tool to get a breakdown of the total number of 502 errors and see how oft and when they are occurring. This tin help y'all troubleshoot if this is an ongoing issue, or perchance something that has resolved itself.

Response analysis 500 error breakdown
Response assay 500 error breakup

8. Restart PHP

Finally, yous can also try restarting PHP. If you're a Kinsta client, you can hands restart PHP from the tools menu within the MyKinsta dashboard. If your host doesn't provide this, you can always open up a support ticket and ask them restart PHP.

Restart PHP
Restart PHP

nine. PHP Timeout Event

PHP timeouts occur if a unmarried PHP procedure runs for longer than the max_execution_time or max_input_time set in the PHP configuration on your server.  This is a mutual occurrence if you're doing big WordPress imports. When this happens a 502 server error is ordinarily displayed. If you run into a PHP timeout these values may need to be elevated.

You lot can check with your current WordPress host about what values are set up on your server and if they tin be increased. On the Kinsta platform, these values are set up to 300 seconds (5 minutes) by default. The maximum PHP timeout values available on our platform are based on your electric current hosting program.

Summary

As you tin can see there are quite a few things you tin can do to troubleshoot and set up a 502 gateway error on your WordPress site. Typically this is non on the client-side, simply rather an issue with your host. Third-political party plugins and themes with bad lawmaking or unoptimized queries are as well things to scout out for. Was in that location anything we missed? Mayhap y'all have another tip on troubleshooting 502 gateway errors. If then, let us know below in the comments.


Save time, costs and maximize site performance with:

  • Instant help from WordPress hosting experts, 24/7.
  • Cloudflare Enterprise integration.
  • Global audition reach with 29 data centers worldwide.
  • Optimization with our congenital-in Awarding Performance Monitoring.

All of that and much more, in ane plan with no long-term contracts, assisted migrations, and a 30-twenty-four hours-coin-dorsum-guarantee. Check out our plans or talk to sales to find the plan that'southward right for you lot.