When it comes to WordPress, there are a lot of different errors that can be downright frustrating and confusing. A few that come to heed are the white screen of decease or the frightening error establishing a database connection. But an even more than popular one is the 502 bad gateway mistake. Why? Because this regularly happens around the entire web, non only to WordPress sites, only fifty-fifty popular services such as Gmail, Twitter, and Cloudflare. But of class, we really only intendance about how it impacts your WordPress site. Read more below nigh what causes this fault and some solutions on how to quickly resolve it.

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

What is a 502 Bad Gateway Error?

The 502 Bad Gateway fault specifically ways that the server received an invalid response from an inbound server.

The Internet Engineering Task Strength (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 inbound server it accessed while attempting to fulfill the request.

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

There are many different types of 500 status error codes (500, 501, 502, 503, 504, 508, 520, etc.) which all have slightly dissimilar meanings. These indicate that the asking was accepted, but the server prevented the fulfillment of the request.

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

502 Bad Gateway Mistake Variations

Due to the various browsers, web servers, and operating systems, a 502 bad gateway error can nowadays itself in a number of different means. But they all have the same meaning. Beneath are just a couple of the many different variations you might see on the web:

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

Another variation you might encounter is a "502 server error."

502 server error in Chrome
502 server mistake in Chrome

And here is yet another variation. "502 – Spider web server received an invalid response while acting as a gateway or proxy server. In that location is a problem with the folio you are looking for, and it cannot be displayed. When the Web server (while interim equally 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 as Twitter might even show a completely different bulletin for a 502 Bad Gateway fault, such as "Twitter is over chapters." This definitely looks a trivial more than user-friendly.

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

And here is a snapshot of how Google displays it. "502. That's an error. The server encountered a temporary error and could non complete your request. Please endeavor again in thirty seconds. That'south all we know."

Google 502 error
Google 502 error

502 Errors Bear upon on SEO

Unlike 503 errors, which are used for WordPress maintenance mode and tell Google to check dorsum at a later fourth dimension, a 502 error tin have a negative impact on SEO if not stock-still right away. If your site is but down for say 10 minutes and it's beingness crawled consistently a lot of times the crawler volition simply get the page delivered from enshroud. Or Google might not even accept a hazard to re-clamber it before it'south back up. In this scenario, you're completely fine.

Notwithstanding, if the site is downward for an extended period of fourth dimension, say half-dozen+ hours, and so Google might meet the 502 error every bit a site level issue that needs to be addressed. This could impact your rankings. If you're worried about repeat 502 errors you lot should figure out why they are happening to brainstorm with. Some of the solutions below can help.

How to Fix the 502 Bad Gateway Error

A 502 bad gateway fault is typically a problem with the network/server, however, information technology tin also exist a client-side outcome. So we'll dive into a petty of both. Check out these common causes and ways to fix the 502 bad gateway error to and become support and running.

1. Try Reloading the Page

One of the easiest and first things y'all should try when encountering a 502 bad gateway error is to simply wait a minute or then andreload the page (F5 or Ctrl + F5). It could be that the host or server is merely overloaded and the site will come correct back. While you're waiting, you could also chop-chop endeavour a different browser to rule that out as an issue.

Some other thing you can practice is to paste the website into downforeveryoneorjustme.com. This website will tell yous if the site is down or if it's a trouble on your side.

downforeveryoneorjustme
downforeveryoneorjustme

2. Clear Your Browser Cache

Whenever you encounter issues similar these it can exist good to clear your browser cache. Below are instructions on how to practice it in the various browsers:

Subscribe Now

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

3. DNS Issue

A 502 gateway error could likewise be because of a DNS outcome, such as the domain is not resolving to the correct IP, or the DNS server is not responding. If you take just migrated your WordPress site to a new host, is it important to wait for things to fully propagate, which can take up to 24 hours in some cases. This depends upon the TTL value of your DNS records.

Y'all tin can as well try flushing your local DNS cache. This is like 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

Yous should run into a "Successfully flushed the DNS resolver Cache" if it worked.

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

dscacheutil -flushcache

Notation: There is no success message on Macs.

And lastly, yous could temporarily change your DNS servers. By default, DNS servers are automatically assigned by your Internet service provider. But yous could endeavour temporarily irresolute these to a public DNS server, such as Googles. In fact, some adopt to use Google's public DNS long-term. If yous have a premium DNS propagation usually is a lot faster.

4. Cheque With Your Host

The primary reason we typically come across a 502 bad gateway fault is due to an upshot with the web host. Sometimes aquery, script, or request will take as well long then it is canceled or killed by the server. A lot of hosts, specially shared hosts implement what they telephone call a "kill script." Basically what this does is information technology will cease a asking afterward a certain catamenia of fourth dimension and so that it doesn't take a site down or touch other users. If you exercise a Twitter search for "bad gateway" you can meet 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 not shared, even between your own sites. This greatly reduces the take a chance of seeing a 502 bad gateway error. We aren't running aggressive impale scripts similar some shared hosts are. And even if one of your sites does happen to go down, it won't impact your other sites.

Another reason you could see a 502 gateway error with your host is likewise due to the fact that the server is simply not reachable, either considering it is downwardly or in that location is no connectivity. In this case, information technology is recommended to check your WordPress host'due south status folio or open a support ticket.

5. Temporarily Disable CDN or Firewall

Information technology could also be an issue with your content delivery network (CDN) or firewall. If you are using a 3rd-party CDN provider an easy mode to troubleshoot this is to just disable your CDN temporarily. For instance, nosotros are big fans of the free CDN enabler plugin. If y'all are using that, you tin merely conciliate the plugin then exam your site. Wp-admin not working? Simply log in to your site via SFTP and rename the plugin's binder to cdn-enabler_old. This will temporarily disable the CDN connection. The same goes for WP Rocket or whatsoever other plugin yous might take 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, equally they have extra firewalls in-betwixt. We have noticed that this happens once in a while on the Cloudflare free plan. Unfortunately, since Cloudflare is a fully proxy service, there is no quick way to merely disable information technology.

However, earlier you lot go blaming Cloudflare, it is of import to know that there are two different types of 502 bad gateway errors variations with Cloudflare every bit seen beneath:

502 Bad Gateway at Cloudflare (Variation 1)

If yous run into the post-obit screen, this is actually a problem on Cloudflare's end, in which example you should reach out to them for support. Yous can also check Cloudflare'southward condition page to meet if they're currently experiencing an outage.

502 bad gateway error
502 bad gateway mistake

502 Bad Gateway at Cloudflare (Variation 2)

If you come across 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 another example with of an HTTP 502 mistake 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. Check Your Plugins and Themes

A lot of times the reason for scripts and queries being canceled past the server is due tobad code on your WordPress site, perchance from a 3rd party plugin or theme. We have also seen a lot of misconfigured caching plugins generate 502 errors. A few ways you can troubleshoot this is by deactivating all your plugins. Remember, yous won't lose any data if you lot but deactivate a plugin.

If you can notwithstanding access your admin, a quick fashion to practise this is to scan to "Plugins" and select "Deactivate" from the bulk deportment menu. This will disable all of your plugins. If this fixes the upshot you lot'll demand to discover the culprit. Start activating them ane past 1, reloading the site after each activation. When you see the 502 gateway error return, you've found the misbehaving plugin. You lot can and then attain out to the plugin programmer for help or post a support ticket in the WordPress repository.

Deactivate all plugins
Conciliate all plugins

If you lot can't access your admin you can FTP into your server and rename your plugins folder to something like plugins_old. And so check your site over again. If it works, then you will demand to test each plugin ane by one. Rename your plugin folder back to "plugins" and then rename each plugin binder inside of if it, one by one, until y'all discover it.

Rename plugin folder
Rename plugin folder

Ever makes certain your plugins, themes, and WordPress core are up to date. And cheque to ensure you are running a supported version of PHP. You tin can always attain out to your host for help. We utilize Kinsta APM and other troubleshooting methods here at Kinsta to help clients narrow downward what plugin, query, or script might exist causing the mistake. You can also use your ain custom New Relic key if y'all have your own license.

Time consuming queries to database
Time-consuming queries to the database

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

7. Check Logs

You lot should also have advantage of your fault logs. If y'all are a Kinsta customer, you tin hands see errors in the log viewer in the MyKinsta dashboard. This can assist yous quickly narrow down the issue, particularly if it'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 tin can also add the following code to your wp-config.php file to enable logging:

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

If you demand more assistance on how to enable WordPress debugging mode here is a full footstep past step tutorial.

The logs are typically located in the /wp-content directory. Others, like here at Kinsta might take a dedicated folder chosen "logs".

wordpress error logs folder sftp

You can as well cheque 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 lot are a Kinsta customer you lot tin besides have advantage of our analytics tool to get a breakdown of the total number of 502 errors and encounter how often and when they are occurring. This can help you troubleshoot if this is an ongoing issue, or perhaps something that has resolved itself.

Response analysis 500 error breakdown
Response assay 500 mistake breakup

viii. Restart PHP

Finally, you can too try restarting PHP. If you're a Kinsta client, you tin easily restart PHP from the tools carte du jour inside the MyKinsta dashboard. If your host doesn't provide this, you can ever open upwardly a support ticket and inquire them restart PHP.

Restart PHP
Restart PHP

ix. PHP Timeout Event

PHP timeouts occur if a single PHP process runs for longer than the max_execution_time or max_input_time set up in the PHP configuration on your server.  This is a common occurrence if you're doing big WordPress imports. When this happens a 502 server fault is normally displayed. If yous run into a PHP timeout these values may need to be elevated.

Yous can bank check with your current WordPress host near what values are gear up on your server and if they can be increased. On the Kinsta platform, these values are set up to 300 seconds (five minutes) by default. The maximum PHP timeout values available on our platform are based on your current hosting programme.

Summary

As yous tin can see in that location are quite a few things y'all tin can do to troubleshoot and fix a 502 gateway error on your WordPress site. Typically this is non on the client-side, but rather an issue with your host. 3rd-party plugins and themes with bad code or unoptimized queries are besides things to watch out for. Was there anything we missed? Possibly you have another tip on troubleshooting 502 gateway errors. If then, let us know below in the comments.


Save fourth dimension, costs and maximize site functioning with:

  • Instant assist from WordPress hosting experts, 24/seven.
  • Cloudflare Enterprise integration.
  • Global audience reach with 29 information centers worldwide.
  • Optimization with our congenital-in Awarding Functioning Monitoring.

All of that and much more, in one plan with no long-term contracts, assisted migrations, and a thirty-day-money-back-guarantee. Check out our plans or talk to sales to notice the program that's correct for you.