This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

The 502 Bad Gateway Error: How to Fix It in WordPress

Updated on May 21, 2026

14 Min Read
fix 502 bad gateway error in wordpress

Key Takeaways

  • A 502 Bad Gateway error usually means the server failed to get a proper response from services like PHP-FPM or Nginx.
  • Start with simple checks first, like refreshing the page, clearing browser cache, or temporarily disabling Cloudflare.
  • If the issue keeps happening, move to server-side fixes like disabling heavy plugins, in

A 502 Bad Gateway error on a WordPress site can be incredibly stressful. It can happen due to various reasons and in almost all cases, it makes the website completely offline for visitors.

More often than not, this error is triggered when a server on the internet receives an invalid or delayed response from another server due to Cloudflare conflicts, maxed out PHP memory limits, or an Nginx timing out.

If your site is facing the WordPress 502 error, I suggest quickly trying one of the troubleshooting steps covered in the TL;DR section to get your site back online.

If that doesn’t work out, go through the detailed solutions I’ve covered in this blog in chronological order and I promise you the error would go away like it never happened.

Quick Troubleshooting (TL;DR)

  • Hard refresh your browser by hitting Ctrl + F5 if you’re on Windows or Cmd + Shift + R on Mac. This will clear your local cache, fixing the error.
  • Open your site in incognito mode to rule out old browser cookies or cache being the cause of the error.
  • Pause Cloudflare or any other CDN you use. If you see Cloudflare on the 502 error screen, temporarily pause it from your Cloudflare dashboard to see if your origin server is working fine.
  • Deactivate all plugins by logging into your server via FTP and rename your plugins folder to plugins_old. This will help you rule out if any plugin is causing a PHP timeout on your site.

Stop Worrying About Server Errors – Host on Cloudways

Cloudways managed hosting handles PHP-FPM, Nginx, and all core server services so you can focus on growing your WordPress site.

What Is the 502 Bad Gateway Error?

502 Bad Gateway error message displayed in a web browser

To understand the 502 Bad Gateway Error, you need to first understand how browsers load data from a server. Okay so, when a user visits a website, the server sends out a request to fetch the data being requested to display in the browser.

If a server responds accurately to the user’s requests, it receives the requested content in return. But, if the request is bad, the 502 Bad Gateway Error shows up on the screen.

For WordPress websites, multiple servers are allocated to run specific tasks. For example:

  • database server to run the WordPress database
  • application server to run PHP and other app-related content
  • reverse proxy server for running Nginx, Apache, Varnish, etc
  • web server to serve website files

Because there are multiple servers involved and all running in parallel, this can complicate the way browsers handle requests. Upon receiving a user’s request, the reverse proxy server fetches data from origin servers while database server, application server, and web server run alongside.

In case any of these servers send an invalid response, the reverse proxy server returns to the browser and displays a 502 Bad Gateway Error.

We often see variations of the 502 Bad Gateway Error on different websites, but they all point to the same issue: the server could not respond to the requests.

Here are some of variations of this error:

  • “502 Bad Gateway”
  • “HTTP Error 502 Bad Gateway”
  • “502 Service Temporarily Overloaded”
  • “Error 502”
  • “502 Proxy Error”
  • “HTTP 502”
  • “502 Bad Gateway NGINX”
  • “502 Server Error: The server encountered a temporary error and could not complete your request”
  • “502. That’s an error. The server encountered a temporary error and could not complete your request. Please try again in 30 seconds. That’s all we know.”
  • “bad gateway the proxy server received an invalid response from an upstream server”
  • “the web server reported a bad gateway error”

Now that we’ve gone over what this common WordPress error is and its variations, let’s move ahead and check out what triggers this error.

Why Does the 502 Bad Gateway Error Occur in WordPress?

Like I briefly mentioned in the beginning, the typical cause of the 502 bad gateway error is when a server fails to respond accurately and instead returns a request with invalid information.

However, there are other possibilities as well that can cause this error. Here are some of the typical culprits:

  • Server may be busy with other tasks or facing traffic spikes
  • Origin server is unresponsive or inaccessible
  • Errors in the database
  • Problem with the reverse proxy server
  • Corrupt PHP scripts in WordPress files
  • Issues with the CDN
  • DNS related issues

How Does a 502 Bad Gateway Affect SEO?

A 502 Bad Gateway error not only frustrates visitors, but can also seriously damage a site’s overall SEO efforts.

Keeping the user experience in mind, if a user clicks a link on a website and instead of the search results, they see an error message, they are going to bounce back to Google and click on a competitor’s link instead.

Search engines track this behavior, and if there is a noticeable pattern, a site’s ranking will drop hard.

Aside from human visitors, bots also constantly crawl websites to index content. If Googlebot for example crawls a site and comes across a 502 error, it can’t read that page.

While a temporary glitch usually doesn’t hurt rankings. But…if a site goes down repeatedly or stays down for hours, search engines can assume the page as permanently broken and might remove it from the search results.

How to Fix a 502 Bad Gateway Error in WordPress

Now that we know a bit more about the wordpress 502 error and what triggers it, let me walk you through the detailed troubleshooting steps to fix it. I recommend you go in order, starting with the easiest browser-level checks and make your way down to advanced server fixes.

1. Do a Hard Refresh and Try Incognito Mode

502 is a server side error, meaning…your browser cannot actually fix it. But, doing a quick hard browser refresh is always a smart first step to make sure you get rid of the error without putting in unnecessary effort.

When a hosting server experiences a brief hiccup, usually 10-15 seconds long during a traffic spike, the server can actually resolve the issue itself. But since browsers aggressively cache, the 502 error screen can go away if you just give the site 60 seconds and then do a force hard refresh.

  • For Windows, you can do a hard refresh by hitting Ctrl + F5.
  • For macOS, you can do the same by hitting Cmd + Shift + R.

If the website still shows the error, open it in an incognito window. This way the browser loads the site without using the stored cache or old cookies.

If the site loads fine in incognito mode, this means your server is healthy and you just need to clear your local browser cache, which I’ll show you how to do in step 2.

2. Clear Your Browser Cache

Since browsers cache website files locally to load pages faster on the next visit, this means they will also sometimes cache temporary error screens and keep serving it to you or your visitors even after the actual server issue has been resolved.

First, confirm if the website is down for you or everyone else. Test the URL on Down for Everyone or Just Me.

If the website is not down, you can purge your local cache like this:

  • For Google Chrome and Microsoft Edge, hit Ctrl + Shift + Del on Windows.
  • Or Cmd + Shift + Delete on Mac.

Make sure you actually select the cached images and files option before you hit the Delete data button.

Chrome clear browsing data dialog with cached images and files option selected

Chrome browser right-click menu showing empty cache and hard reload option

Once done, reload your website. If the error is still there, it’s time I walk you through the network and server fixes next.

3. Check for a Cloudflare 502 Bad Gateway Error

If you use a CDN like Cloudflare, the 502 error can be because of it. CDNs sit between your visitors and your hosting server. Since it acts like a middleman, any error in communication will trigger a Cloudflare 502 bad gateway error.

Cloudflare 502 error page showing red X next to the Host icon

If you see a red X next to the Host icon like in the screenshot above, this means Cloudflare is working perfectly fine but your web server is rejecting the connection.

To confirm if the CDN layer is the cause of the error, you can temporarily pause cloudflare by logging into your Cloudflare, select your domain, and click on Pause Cloudflare on Site.

Cloudflare dashboard overview page showing Pause Cloudflare on Site option

Then, wait a few minutes and reload your site. If the error goes away, this confirms that the CDN is the culprit.

The reason why this error occurs due to Cloudflare is because of its SSL settings. If configured incorrectly, like for example set to Full (Strict) without a valid origin certificate. In this case, changing the mode from Full (Strict) to Full usually fixes the issue.

Cloudflare SSL/TLS settings page showing Full and Full Strict encryption mode options

If your site is still down even after pausing Cloudflare, the problem is definitely on your origin server side.

4. Clear Your Local DNS Cache

DNS links your domain name to your server’s IP address. In case your domain fails to resolve to the correct IP, it can trigger the 502 Bad Gateway error.

This happens typically if you migrated your WordPress site to a new host and changed your nameservers. Since DNS propagation takes up to 24 hours, if you access your site during this window, you’ll probably see the 502 error.

And in case you haven’t made any host migrations and you still see the error, your computer might be holding onto either outdated or completely corrupted DNS cache.

In this case, you can flush the cache from your computer so that your browser looks up the correct IP address.

  • On Windows, open Command Prompt and run this command: ipconfig /flushdns

Windows Command Prompt showing ipconfig /flushdns command to clear DNS cache

  • If you use Mac, run this command in Terminal: dscacheutil -flushcache

Mac Terminal showing dscacheutil -flushcache command to flush local DNS cache

Once cleared, load your website again. If the website still shows a 502 error, this means local cache and network issues are not the cause of the problem. So…it is time to look directly at WordPress files and server settings. Let’s check that out next.

5. Audit Your WordPress Plugins and Themes

Another cause of the error could be due to plugins and themes. If a plugin script takes too long to run a request, a server kills the process and returns a 502 error code.

Since the 502 error usually blocks you from logging into the WordPress admin dashboard, you’ll have to deactivate plugins manually. You can do this using an FTP client like FileZilla or through the control panel’s file manager provided by your hosting provider.

If you use FileZilla, after connecting to your server, go to your root directory where your public_html folder is. Then go to the wp-content folder and find the plugins folder.

Rename the plugins folder to something like plugins_disabled. Once you do this, all of your plugins will be disabled.

FileZilla FTP client showing WordPress plugins folder renamed to plugins_disabled in wp-content

Now, check your website again. If it loads, you know a plugin is the problem. But to find the exact plugin, you can rename the folder back to just plugins. Then, you’d have to do some tedious work opening the plugins folder and renaming each plugin directory one by one. And after each change, you’ll need to check your site until you see the error again. Once you find the culprit, update the plugin or re-install it.

And in case none of the plugins are causing the issue, you’ll need to try the same fix for your themes. You can do this by going to wp-content/themes and renaming your active theme’s folder.

What this does is that it forces WordPress to revert to the default theme. Once you do this, refresh your site. If you see a blank white screen or some basic layout instead of the error, your custom theme was causing the issue.

Tired of Plugin and Server Conflicts? Try Cloudways

Cloudways optimizes your server stack so your plugins run without causing 502 errors or timeout issues.

6. Regenerate Your .htaccess File

If your server runs on Apache and your .htaccess file can mess up communication between your server and your browser. This results in a 502 Bad Gateway error.

To check if the .htaccess file is the problem, you connect to your site using an FTP tool or the file manager provided by your hosting provider. And just like we did in the previous step, go to the root folder, usually public_html.

Here you’ll find the .htaccess file. In case you don’t see the file, you have to enable the option to view hidden files in your FTP client.

FileZilla FTP client showing .htaccess file in WordPress public_html root directory

Once you find the file, rename it to something like .htaccess_changed.

Then go back to your browser and refresh the website. If the error goes away, and your site loads, the corrupted .htaccess file is the problem.

To fix this, log into the WordPress dashboard, then go to Settings > Permalinks. Once one Permalinks screen, don’t change any settings. Just scroll all the way to the bottom and click the Save Changes button.

This tells WordPress to generate a clean .htaccess file for your server. Now if you go back to your site, it should load normally.

7. Increase PHP Memory Limit and Execution Time

502 error is also triggered when heavy PHP processes take too long to run. Or they need more memory than what your server allows.

Tasks like complete website backups, image optimization in bulk, or using heavy WooCommerce import tools can easily max out your site’s PHP memory limit. So…when PHP hits its max allocated limit, your server ends the process and shows a bad gateway error.

To fix this, the first thing you should do is increase the PHP memory limit. As we did earlier, use an FTP client to connect to your site, but this time, locate the wp-config.php file.

FileZilla FTP client showing wp-config.php file in WordPress root directory

Download this file and open it in a text editor like notepad.

Add the following code just above where it says: “That’s all, stop editing! Happy publishing.”:

define( 'WP_MEMORY_LIMIT', '256M' );

WordPress wp-config.php file with WP_MEMORY_LIMIT constant set to 256M

Now save the file and upload it back to your server, replacing the old file. Once done, check your site. If this fix did not solve the error, the scripts might need more time to finish running.

To fix this issue now, increase the maximum execution time. For this, you’ll need to edit your .htaccess file and paste the code below at the very end:

php_value max_execution_time 300

And while you’re adjusting limits, go to your hosting control panel, and check your PHP version. In case it is outdated, it can cause conflicts with modern WordPress plugins. So, make sure you update to the latest PHP version like PHP 8.1, 8.2, or 8.3.

Cloudways users can upgrade PHP versions directly from the Server Management panel of the dashboard to prevent compatibility related errors.

Cloudways Server Management panel showing PHP version upgrade options

8. Troubleshoot Nginx and OpenResty (Restart PHP-FPM)

If your server runs on Nginx or OpenResty instead of Apache, 502 error could be due PHP-FPM crashing or not responding properly.

Nginx works as a reverse proxy and passes PHP requests to PHP-FPM. And when PHP-FPM crashes, gets bombarded by traffic, or just takes too long to process, Nginx drops the request and throws a 502 error.

The fastest way to fix this is to just restart the PHP-FPM service. If you use a managed host like Cloudways, you can restart PHP-FPM right inside the hosting dashboard.

Cloudways hosting dashboard showing PHP-FPM service restart button

If you have an unmanaged VPS setup, and have SSH access to your server, you can login to  your SSH terminal and restart the service by running this command:

sudo service php8.2-fpm restart

You can change “8.2” in the code above with whatever PHP version your server is currently running.

After running the command, restart Nginx too. You can do this by using this command:

sudo service nginx restart

Or if you’re on Cloudways, you can do this in the Manage Services section of your server setting.

Cloudways Manage Services section showing Nginx and PHP-FPM service controls

If the 502 error is still there even after restarting PHP-FPM and nginx, then the FastCGI buffer of your server might be too small. This can prevent it from handling large response headers generated by some WordPress plugins.

You can increase the buffer size by opening the nginx.conf file and adding the two commands mentioned below inside the http, server, or the location block:

fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;

After updating the file, save it and then restart Nginx one last time to apply the changes we just made in the nginx.conf file.

9. How to Fix 502 Bad Gateway in Local WP (Flywheel)

Sometimes the 502 error can also appear on local setup. For example, if you are building a website offline on Local by Flywheel, and you see the error, your local router may be failing to connect to your website, or another app on your computer could be using the same port.

To fix this, click the Stop Site button in your Local dashboard and wait a few seconds.

Local by Flywheel dashboard showing Stop Site button to restart local server

Then click the Start Site button and let the local PHP and Nginx containers restart. This will clear out temporary glitches and hopefully get rid of the 502 error.

If the error is still there, there might be a port conflict. To fix this, you’ll need to change your router settings. To do this, go back to Local WP > main menu icon > Preferences. Then go to the Advanced tab.

Here, look for Router Mode setting and then change the option for Site Domains to Localhost. Finally hit Apply and then restart your local site. This change almost always fixes the local 502 error.

Local WP Preferences Advanced tab showing Router Mode set to Localhost for Site Domains

10. Check Your Error Logs and Contact Your Host

Lastly, a 502 error can also be triggered because of a plugin conflict or an issue with your database that doesn’t trigger a normal PHP timeout. To figure out what’s actually failing, triggering the error, you’ll have to enable WordPress debug mode.

To enable debugging mode, connect to your server using an FTP client and open the wp-config.php file.

WordPress wp-config.php file showing WP_DEBUG constant set to false

In this file, replace “define( ‘WP_DEBUG’, false );” with the code snippet below:

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

WordPress wp-config.php file with WP_DEBUG, WP_DEBUG_LOG, and WP_DEBUG_DISPLAY constants enabled

Save the file and upload it back to your server. After that, refresh your website. This will not fix the error, but actually trigger it again instead, which is exactly what we want.

Now, go back to your FTP client, and go to the wp-content folder. Here, look for a newly created file named debug.log.

Open the file and check out the recent entries. Look for phrases like “fatal error” or “timeout” since they usually point to the exact plugin, theme, or file causing problems.

If you see no errors in the log file and have tried all the solutions to no avail, the problem is officially out of your hands. In this case, your best bet will be to contact your hosting provider.

In the case of Cloudways customers, when they open a support ticket, our engineers typically respond in under 60 seconds and offer an average resolution time of less than 45 minutes.

Conclusion

A 502 Bad Gateway Error happens when your server fails to get a proper response from background services like PHP-FPM or Nginx. It can turn into a critical problem, especially since it makes your site unavailable for visitors.

In this guide, I covered a bunch of targeted fixes in proper sequence, to help you effectively pinpoint the cause of the error and get rid of it.

We talked about running basic checks like refreshing the browser, clearing cache, and reviewing error logs.

And we covered server-level fixes like disabling plugins and themes to find the source of the issue, restarting services like Nginx, PHP-FPM, and increasing server resource limits during traffic spikes.

If none of the fixes worked for you, you should contact your hosting provider. And if you have any questions or confusion, leave them in the comments and I’ll get back to you ASAP.

Let Cloudways Handle Your Server — Focus on Your Business

Our support team responds in under 60 seconds and resolves most issues in under 45 minutes.

Q. How do I fix a 502 Bad Gateway error?

Fix the 502 error by refreshing your site first, then clear your cache, and disabling any CDN temporarily. If it is due to a server-side issue, check your server logs, restart PHP-FPM or Nginx, and disable faulty plugins.

Q. Does a 502 Bad Gateway mean I am blocked?

No. A block usually shows a 403 error, rather than a 502 error. A 502 means the server did not receive a valid response from another service that it is dependent on.

Q. How do I fix a 502 Bad Gateway issue permanently?

You can prevent the 502 error by upgrading your server resources, optimizing your plugins, and updating PHP and server software.

Q. Is a 502 error a security problem?

No, it is not a security risk. It is a server side communication issue. Although, high traffic or DDoS activity can sometimes trigger the 502 error indirectly.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdul Rehman

Abdul is a tech-savvy, coffee-fueled, and creatively driven marketer who loves keeping up with the latest software updates and tech gadgets. He's also a skilled technical writer who can explain complex concepts simply for a broad audience. Abdul enjoys sharing his knowledge of the Cloud industry through user manuals, documentation, and blog posts.

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour