502 Bad Gateway Error and How to Fix It

HTTP 504 Gateway Timeout and HTTP 502 Bad Gateway errors are the most common server errors for WordPress website visitors and owners. In my previous article, we discussed the causes of a 504 Gateway Timeout error and possible solutions. In this article, we’ll come to understand what a 502 Bad Gateway error is, talk about the reasons for a 502 Bad Gateway error, and explore some tips for troubleshooting this type of error.

What does 502 Bad Gateway mean?

Before we define a 502 Bad Gateway error, let’s deep-dive into server infrastructure and find the meaning of some terms, like web server, proxy server or gateway, and upstream server.

Let’s first discuss how hosting a modern web application works. We need three actors for this:

  1. The web application
  2. The gateway
  3. The web server

In the picture below you can see the PHP modern web application workflow.

web application workflow

A web application is software that can be coded in different programming languages and can use specific frameworks or libraries. It typically has tools to handle HyperText Transfer Protocol (HTTP) requests. For your WordPress website, the web application is your WordPress installation, which is coded in PHP.

The gateway sits between a web server (Nginx, Apache) and a web application. It accepts requests from a web server and translates them for a web application. The exact definition of a gateway is fluid. Some call themselves process managers, and some call themselves HTTP servers.

Here’s what the common functionality of a gateway entails:

  • Listening for requests (HTTP, FastCGI, uWSGI, and more)
  • Translating requests to application code
  • Spawning multiple processes and/or threads of applications
  • Monitoring spawned processes
  • Loading balance requests between processes
  • Reporting/logging

PHP-FPM (PHP-FastCGI Process Manager) is the gateway for PHP. It is an implementation of FastCGI and will listen for FastCGI requests from a web server.

FastCGI is a binary protocol for interfacing interactive programs with a web server. CGI (Common Gateway Interface) is a web technology and protocol that describes how a web server can communicate with external applications, e.g., PHP. CGI is an interface between the web server and the dynamic web content generated by web applications written in different programming languages, such as PHP and Python.

FastCGI is an improved version of CGI.

A modern way to run PHP applications is to use PHP-FPM. Before PHP-FPM, PHP was commonly run directly in Apache. There was no need for a gateway. Apache’s PHP module loaded PHP directly, allowing PHP to be run in line with any processed files.

The web server generally hosts multiple sites, serves static files, proxies requests to other processes, and performs load balancing and HTTP caching. The most popular web servers are Apache and Nginx. Apache was the most widespread web server until Nginx became more popular.

At 10Web, we support the LEMP stack, which is similar to LAMP (Linux, Apache, MySQL, and PHP), except Nginx replaces Apache.

What happens when you open your WordPress website hosted by 10Web in your browser? The web server, in this case, Nginx, accepts a request and relays it to PHP-FPM, which in turn interprets the PHP code. The response is relayed back, finally reaching the client.

In this case, Ngnix acts like a proxy server, which is usually called an edge server. The server behind the proxy server is called the upstream or origin server. In this case, PHP-FPM acts as an upstream server.

Now that we fully understand the terms mentioned above let’s finally understand the 502 Bad Gateway error.

What is a 502 Bad Gateway error?

We face a 502 Bad Gateway error when the web server acts as a proxy server and receives an invalid response from the upstream server. A 502 Bad Gateway error indicates that the proxy server, which is the edge server, could not get a valid response from the upstream server, which is the origin server.

When you see a 502 Bad Gateway error, it means that something is wrong with the upstream server. The server notifies you with an HTTP status code, such as a 502 bad gateway error, indicating the nature of the problem.

A 502 error is part of a series of 500 status error codes (500, 501, 502, 503, 504, 508, 520, etc.) that indicate different server-side issues preventing the fulfillment of the request.

The various forms of 502 errors

A 502 Bad Gateway error can appear differently depending on the operating system, web browser, and device. Each combination can interpret and display the error uniquely, though the underlying issue is the same.

Here’s how it looks most of the time:

502 bad gateway error

Users might encounter several distinct messages, each a variation of the 502 error, such as:

502 Bad Gateway: the most common variation.

Error 502: A simplified version often used by various browsers.

HTTP Error 502 – Bad Gateway: A more descriptive version, typically seen in browsers with detailed error reporting.

502 Service Temporarily Overloaded: Indicates server overload, common in high-traffic scenarios.

502 Proxy Error: Seen in environments where proxy servers are used.

A blank white screen: A less informative variant, sometimes due to the server’s or browser’s minimalistic error handling.

502 Server Error: The server encountered a temporary error and could not complete your request.: This detailed message provides insights into the problem’s temporary nature.

HTTP 502: A concise version common in various web applications.

Temporary Error (502): This signifies the temporary aspect of the error.

502. That’s an error: A user-friendly variant, often accompanied by additional instructions, as seen with Google’s services.

502 bad gateway Cloudflare: Specific to Cloudflare services, indicating issues with the Cloudflare network.

Bad Gateway: The proxy server received an invalid response from an upstream server.” This detailed description is often seen in environments with multiple server layers.

502 server error: Another general form of the error message.

502 – Web server received an invalid response while acting as a gateway or proxy server: This version provides a comprehensive explanation, indicating the server’s role and the nature of the issue.

Custom 502 pages

Some services and sites customize their 502 error messages for user-friendliness.

Google presents a message such as 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—combining error information with a user action suggestion.

Google 502 Bad Gateway error

Twitter might display a message like “Twitter is over capacity,” a more user-centric way of communicating the issue.

Twitter's custom 502 bad gateway error page.

What are the reasons behind the 502 Bad Gateway error?

The 5xx status codes indicate that there are problems with the server, and 502 is not an exception. For some reason, the proxy server can’t get a response or a valid response from the upstream server. This lack of response could be due to various problems:

DNS issues – Incorrect DNS settings can render a server unreachable, contributing to this error.

Firewall blocks – Firewalls that incorrectly identify and block communication between servers can cause a 502 error. This might happen if the firewall detects false threats and blocks certain internet providers or IP addresses.

Browser problems – Outdated browser versions or corrupted files in the browser cache can sometimes trigger 502 errors, though this is less common.

Server Overload – This issue arises when the server hosting the website runs out of resources, potentially due to an unexpected spike in traffic or low memory, leading to crashes and resulting in a 502 error.

Network errors and hosting issues – Problems in the network, including issues with routers, modems, or other network devices, can lead to a 502 Bad Gateway error.

Faulty plugins or themes – Bugs in the website’s code or problems with third-party services that the website depends on are common sources of this error.

Server software timeouts – A 502 error may occur if a server takes too long to respond, leading the other server to time out.

In your WordPress website with Nginx/PHP-FPM stack, a 502 error can happen when PHP-FPM is not running, or Nginx can’t communicate with PHP-FPM for some reason. Your hosting provider should check this case. Another reason could be PHP-FPM timeout issues, which we’ll discuss down the line.

Any misunderstanding between Nginx and PHP-FPM can lead to a 502 Bad Gateway error.

Though these errors are often connected to server-side issues, there are some tips for troubleshooting on the client side.

Let’s go over both client- and server-side troubleshooting.

How to Troubleshoot a 502 error message

It is important to note that a 502 error usually requires a fix by the web server or the proxies you are trying to access. In other words, the problem is probably not on your end, but there are steps you can take to try fixing these types of server errors.

Here are some straightforward ways of fixing 502 Bad Gateway errors from the client side.

Reload the page

You should first reload the page (F5 or Ctrl + R) and wait for a minute. If the 502 Bad Gateway error disappears, it means there was a temporary problem with the upstream server or the networking between servers. If the error remains, check if the site is down for everyone.

Check if the website is down

Ask friends or use services online to check if the website is down for everyone, which would confirm that the issue is on the website’s end.

You can use Is it down right now? for this. If the website works for others but not for you, you can try other basic troubleshooting steps.

Try a different browser

Sometimes, the issue might be related to the browser you’re using. Switch to a different web browser and see if the problem persists. For example, switching from Google Chrome to Firefox or Microsoft Edge.

Checking in an incognito window

Open the site in an incognito or private browsing window to rule out browser extensions or cookie issues. To try this in Chrome:

  1. Press ctrl + shift + N, or
  2. Click on the 3 vertical dots in Chrome’s upper right corner and choose New Incognito window.
  3. Try visiting the website with the 502 error.

If the website loads in an incognito window, there may be an issue caused by cached data or a rogue extension.

Check using a different device

Try accessing the site from another device to see if the issue is device-specific. Try visiting the website with the 502 error using your mobile device’s connection. Turn off the mobile’s Wi-Fi to ensure it’s using the mobile data connection.

Suppose the site loads on a different device. In that case, you’ll know you need to look closer at browser extensions or cached network data interfering with the website on the first device. If the site still doesn’t load correctly, it strongly indicates that the issue isn’t on your end, and you may have to wait until the website is back up and running. In the meantime, there are other troubleshooting steps you can try.

Check your internet connection

Ensure your internet connection is stable and working with a fresh start. Try restarting your modem, router, computer, or the device you’re having trouble with. This can help clear out any retained data that can cause 502 errors.

  1. Shut down your computer.
  2. Unplug the modem and router for about 30 seconds to ensure they power down fully.
  3. Plug everything back in, and give it a few minutes for both devices to start back up.
  4. Turn your computer back on.
  5. Once you’re back online, try rechecking the website.

If none of the above steps fix the error, you’ll have ruled out many possible problems with your local network. However, there are a couple more places where caching can cause problems.

Clear browser cache and cookies

Problems with cached browser data or cookies can cause 502 errors. Clearing your browser’s cache and cookies might resolve the issue if the page loads in an incognito or private browsing window.

Here’s how to clear Chrome’s cache:

  1. Enter chrome://settings/clearBrowserData in the address bar or
  2. Click on the 3 vertical dots in Chrome’s upper right corner and choose History
  3. Click on Clear browsing dataClearing Chrome's browsing data.
  4. Tick all the boxes to ensure the cache is totally cleared
  5. Select the Time Range from the drop-down menu
  6. Click Clear dataChrome clear browser cache window selected for all time.

This will clear all the browser’s stored data it uses to speed up performance. Try visiting the website with the 502 error again to see if clearing the cache resolved the problem.

Flush DNS cache

The 502 Bad Gateway error can occur because of DNS issues. Operating systems, such as Linux, Windows, and macOS, save name resolution information in the form of a DNS cache. Clearing the DNS cache can often solve a 502 Bad Gateway error. In particular, if your site is experiencing the error and you’ve just switched hosting or changed the domain’s DNS records, flushing your computer’s DNS cache and allowing ample time for DNS propagation can help fix the error.

Here are the commands which you can use for flushing the DNS cache on Windows, macOS, and Linux.

Windows Use these commands to flush the cache on Windows:

ipconfig /flushdns

You can do this by opening a Command Prompt.

  1. Press the Windows key
  2. Type cmd and press Enter
  3. Type ipconfig /flushdns in the command prompt and press Enter

You’ll then see a message stating Successfully flushed the DNS Resover Cache.
Flushing dns in command prompt.

mac On macOS, you should open the terminal and type:

sudo killall -HUP mDNSResponder

There’s no message after processing this command, but you can add your own by running the command like this:

sudo killall -HUP mDNSResponder && echo macOS DNS Cache Reset
  1. Click on Go in the toolbar
  2. Select Utilities
  3. Open Terminal
  4. Type sudo killall -HUP mDNSResponder && echo macOS DNS Cache Reset and hit Enter.
  5. Enter your admin password when prompted.
    Terminal on a Mac showing the command for flushing DNS.

Things are different in Linux, as Linux distributions use various DNS services. Some are NSCD (Name Service Caching Daemon), dnsmasq, and BIND (Berkeley Internet Name Domain). For an NSCD DNS cache:

sudo /etc/init.d/nscd restart

For a dnsmasq DNS cache:

sudo /etc/init.d/dnsmasq restart

For a BIND DNS cache:

sudo /etc/init.d/named restart
sudo rndc restart
sudo rndc exec

If the terminal asks for your password, just enter it.

After you’ve flushed your computer’s DNS cache, visit the website experiencing the issue again.

Change DNS servers

Try changing your DNS servers to check if you’re having trouble with your DNS. You can switch to a public DNS service like Google DNS or OpenDNS.

  • Google Public DNS: or
  • Cloudflare DNS: or
  • OpenDNS Home: or
  • AdGuard DNS: or
  • Quad9: or

You can find more information about changing DNS servers in this article: Change your DNS servers settings.

Before making changes to your DNS, remember to note your current DNS settings and IP addresses in case you want to revert back to your original setup after troubleshooting. A few screenshots taken before changes may prove helpful for reference.

Windows Windows

  1. Click on Start > Settings > Network & Internet
  2. Select your internet connection (for example, your current Wi-Fi network)
  3. Click Hardware properties
  4. Click Edit next to DNS server assignment
  5. Switch from Automatic to Manual
  6. Select IPv4 or IPv6 (whichever your ISP requires)
  7. Enter the new DNS server IP addresses in the Preferred DNS field.
  8. Enable encryption, if available.
  9. Click Save.

mac Mac

  1. Click the Apple logo > System Settings > Network
  2. Select your internet connection (for example, your current Wi-Fi network)
  3. Click Details
  4. Open the DNS tab in the pop-up window
  5. Change the IPv4 or IPv6 addresses, or
  6. Click + to add new DNS server addresses
  7. Click OK
    Settings in the Mac system where DNS servers can be changed

Check to see if changing the DNS servers resolved the problem. If not, switch back to your original DNS settings. If you already use custom DNS, consider switching to your ISP’s default DNS servers to see if that fixes the problem.

Disable VPN or proxy

Many people use a VPN or web proxy to protect their private information. These services can interfere with some websites and cause 502 errors, even if configured and working correctly. If you’re using a VPN or proxy, try disabling it.

Most VPN services make turning your VPN connection on or off easy. For example, to disconnect from your VPN using OpenVPN in Windows:

  1. Click on the system tray
  2. Click the OpenVPN icon
  3. Toggle the connection off to disconnect

When turning off your VPN, remember to switch it back on after browsing or troubleshooting.

Turning off VPN connection in OpenVPN.

Alternatively, take a look at your proxy settings to check for issues.

Windows Windows

  1. Click the Windows shortcut key
  2. Type Control Panel and press Enter
  3. Click Internet Options
  4. Click Connections > LAN Settings
  5. Uncheck the boxes for Automatically detect settings and Use proxy server for LAN
  6. Click OK

mac Mac

  1. Click on the Apple icon on the top left and choose System Settings
  2. Click on Network
  3. Select the network you’re using (usually Wi-Fi or Ethernet)Turning proxy off on a Mac.
  4. Click Details
  5. Click the Proxies tab
  6. Turn off all toggles for the different proxy protocols listed
    Toggles to turn off proxy on Mac.

Check for updates

Ensure your browser and any related plugins or extensions are up to date. Outdated software can lead to various issues, including 502 errors. For example, you can try taking a look at Chrome’s extensions:

  1. Enter chrome://extensions/ in the address bar or
  2. Click on the 3 dot menu in Chrome’s upper right corner.
  3. Select Extensions > Manage Extensions.Chrome menu - Extensions - Manage Extensions to turn extensions off.
  4. Scan the installed extensions and consider uninstalling any that are unneeded.
  5. Scan the remaining extensions for any that haven’t had a recent update. If they haven’t been updated in the last 3 months, it may be time to get rid of them.
  6. Use the toggles to turn off each extension, and try loading the website with the error.
  7. If the website works, you know there’s an issue with an extension.
  8. Try turning them on one by one, testing the 502 website error each time until you find the problematic extension.

Remember, if none of these methods work, the problem is likely on the server side, and only the website’s admin or owner can fix it. In that case, you’ll have to wait and try accessing the site later.

Impact of 502 errors on SEO

A 502 Bad Gateway error can negatively affect your website’s search engine optimization (SEO). If the site’s down, neither visitors nor search engine crawlers can access it.

Short-term vs. long-term downtime

Suppose your site experiences a 502 error but is down briefly, like 10 minutes. In that case, the impact on SEO might be minimal. This is because search engines might retrieve the page from the cache during this downtime if your site is crawled frequently.

If the site recovers before Google’s re-crawl, it’s unlikely to be negatively impacted. However, the implications are more severe if the site remains down for an extended period, say over 6 hours.

Extended downtime could lead Google to perceive the 502 error as a significant issue, potentially harming your site’s rankings. If 502 errors occur repeatedly or persist for extended periods, it’s crucial to investigate and resolve the underlying causes to avoid long-term SEO damage.

Mitigating SEO impact

To mitigate the SEO impact of 502 errors and prevent their recurrence on your own websites, consider the following solutions:

Diagnose the cause

Identifying the root cause of the 502 errors should be a priority. Common culprits include server overload, network issues, or faulty server configurations. Third-party plugins and themes are often to blame for 502 errors on WordPress sites.

Improve server reliability

Upgrade your hosting solution or optimize server resources to handle traffic spikes effectively.

Optimize web application

Regularly update and maintain your web application to prevent bugs that might lead to 502 errors.

Use a CDN

Implement a Content Delivery Network (CDN) to distribute traffic load and provide an additional layer of reliability.

Monitor website uptime

Use website monitoring tools to get alerts when your site goes down, allowing for quicker response and resolution.

Implement good error handling

Customize your 502 error page to inform users and search engines that the issue is temporary and provide alternative navigation options.

Here’s how you can get your website back up and running when you see 502 bad gateway errors on your own site.

Correcting 502 errors on your website

Several common pitfalls can cause a WordPress website to show 502 bad gateway errors. If the task of getting your website back up and running falls to you, here are some recommendations for tracking down problems that lead to these types of errors.

Check server health

Ensure your server is not overloaded or experiencing downtime. Contact your hosting provider for assistance or check the host’s status page.

Depending on your web host’s policies and configuration, the server may automatically stop any processes or requests that take too long. This can lead to timeout errors. Additional or similar procedures may be in place to prevent the whole site from going down or bogging down the shared server for other websites. These types of configurations can lead to 502 errors.

Higher-quality web hosting typically uses containerized architecture to eliminate these types of issues with shared hosting. This way, even if one site experiences a problem or downtime, it doesn’t affect your other sites.

Review recent changes

If the error started after a recent change (like software updates or configuration changes), revert those changes to see if it resolves the issue.

You may have recently changed your domain’s DNS records or migrated your website to new hosting. In that case, you may need to wait until the new records propagate throughout the DNS system. Time for this process varies, but give it at least 24 hours to complete.

Restart PHP

WordPress sites run on PHP. If your server’s PHP engine isn’t working correctly, the site won’t be able to function properly. Depending on your web host, you may be able to restart the PHP engine from your hosting control panel or dashboard.

Restarting PHP engine in web hosting panel.

With 10Web, you can do this by going to Hosting Services > Tools and clicking the blue “Restart PHP” button.

If your hosting doesn’t provide an interface for restarting PHP, ask them to do it for you.

Restart PHP-FPM service

You will get a 502 error if the PHP-FPM service is inactive or not running on your server. If you have access to your hosting, you can check this by running one of the following commands. For SysVinit:

sudo service php7.4-fpm status

For SystemD:

sudo systemctl status php7.4-fpm

If the service is active and running, the output of the command should be like this:

fixing 502 bad gateway error server-side

If the status is not Active: active(running), try restarting PHP-FPM service to resolve the error using one of the following commands. For SysVinit:

sudo service php7.4-fpm restart

For SystemD:

sudo systemctl restart php7.4-fpm

Timeout issues

A PHP-FPM timeout can cause the 502 error. If your application takes too long to respond, users will experience a timeout error. If the PHP-FPM timeout is less than Nginx timeout, Nginx will return a 502 Bad Gateway error. To avoid this, you can increase PHP-FPM timeout if you can access your server.

PHP-FPM timeout is set in pool configuration, which is


The default value for this directive is 20 seconds. If you can’t access your server, ask your hosting provider to check it. To avoid getting 504 errors after increasing PHP-FPM timeout which can be because of Nginx timeout, the default is 60 seconds, you can increase fastcgi_read_timeout directive in /etc/nginx/nginx.conf file. Don’t forget to reload the Nginx server after changing the directive:

nginx -s reload

PHP execution time errors can also lead to 502 Bad Gateway errors. To avoid this, you can increase the PHP configs, such as max_exexution_time and max_input_time.

If you have server access, just change these directives in your php.ini file. If not, ask your hosting provider to do it for you.

Update WordPress, plugins, and themes

Outdated WordPress core, plugins, or themes can cause compatibility issues, leading to 502 errors. Regularly update them to the latest versions in the WordPress admin.

It’s always a good idea to back up your website before installing any updates. If something’s broken after updating, you can restore the backup and work on figuring out what went wrong.

Here’s how to check for available updates and install them in bulk.

  1. Log in to your WordPress admin. (e.g., yourdomain.com/wp-admin)
  2. Hover over Dashboard in the left navigation and click Updates in the pop-upUpdates page in WordPress admin navigation under Dashboard.
  3. Scan the page for available updatesUpdates page in the WordPress admin.
  4. Use the tick boxes to select plugins and themes with updates
  5. Select Update in the drop-down menu
  6. Click Apply

Consult server logs

Server logs can provide detailed insights into the root cause of the issue.

Logs in the 10Web dashboard.

Particularly in the case of a conflicting plugin or theme, the error log can direct you to a file path associated with the error.

With 10Web, you can easily check server logs by going to Hosting Services > Logs. You can check server logs directly if you have access to your file system. In the case of the Nginx web server, you can find logs here:


In the case of Apache web server, the logs are in this repository:


Scan the logs for errors containing file paths like wp-content/plugins or wp-content/themes. If you find one, you’ll know which plugin or theme to deactivate for troubleshooting. You may also find PHP timeout errors, which can cause 502 bad gateway errors.

Check plugins and themes for conflicts

Sometimes, non-optimal codes in WordPress plugins and themes can cause 502 errors. If you can’t find the culprit in the server logs, try to deactivate all plugins and revert to a default theme (like Twenty Twenty-One). If the error resolves, reactivate each one by one to identify the source of the error.

Testing plugins when you can access the WordPress admin

If you can access yoursite.com/wp-admin, you can try deactivating the plugin or theme found in the error log. If your error log search didn’t turn up anything useful, you can deactivate all the plugins in bulk from the Plugins page.

  1. Log in to your WordPress admin account
  2. Go to PluginsDeactivating plugins in the WordPress admin.
  3. Tick the box to select all plugins
  4. Select Deactivate from the Bulk Actions drop-down menu
  5. Click Apply.

Test the site, and if it works, start reactivating the plugins one by one, checking the site each time for the 502 error until it reappears. After you activate the problem plugin and see the error again, you’ll know which one is causing the error. You can then contact the plugin’s developer for help or ask for assistance in the plugin or theme’s WordPress support forum.

Testing plugins when you cannot access the WordPress admin

If you can’t access the WordPress admin, you’ll need to use FTP to access your website’s files on the server. You can use an FTP client like FileZilla to do that.

  1. Find your FTP credentials from your web host
  2. Use an FTP client like FileZilla to access your website files.
  3. Rename your wp-content/plugins folder to disable all plugins, or if you found a particular plugin or theme in the error log, you can rename that specific folder instead of renaming the plugins folder.Renaming the WordPress plugins folder via FTP for troubleshooting.
  4. Test the site with the 502 error.
  5. If the site works, reactivate the plugins by changing the folder’s name back to plugins.
  6. Repeat the process of deactivating plugins or themes by renaming the respective folder and testing the site for the error until you find the problematic plugin.

Once you’ve found the plugin or theme causing the error, you can contact the developer or ask for help in the plugin’s or theme’s WordPress forum.

And don’t forget to keep your plugins, theme, and WordPress core up-to-date. This will help you avoid many problems, including 502 errors.

Increase PHP memory limit

Sometimes, insufficient PHP memory can cause 502 errors. Increase the PHP memory limit in the wp-config.php file by adding this line:

define(‘WP_MEMORY_LIMIT’, ‘256M’);

You can edit the wp-config.php file via FTP or your web hosting’s file manager. For example, with FileZilla:

  1. Find your FTP credentials from your web host
  2. Use an FTP client like FileZilla to access your website files.
  3. Navigate to your WordPress files and scan the list for wp-config.php.wp-config.php shown in an FTP client.
  4. Right-click the wp-config.php file and select Download to save a copy
  5. Right-click the wp-config.php file again and select View/Edit
  6. Search the file’s code for a line like define(‘WP_MEMORY_LIMIT’, ‘128M’);
  7. If you don’t find the line, add it to the end of the file above where it says /* That’s all, stop editing! Happy publishing. */
  8. Make sure the number at the line’s end is 256M
  9. Save the file

Check .htaccess file

Incorrect rules in the .htaccess file can lead to 502 errors. Try restoring it to default to see if it resolves the issue. Like the wp-config.php file, you can access the .htaccess file via FTP or your web host’s file manager. Here’s an example of backing up the .htaccess file and renaming it for troubleshooting.

  1. Find your FTP credentials from your web host
  2. Use an FTP client like FileZilla to access your website files.
  3. Search for .htaccess in the file names. The exact location varies between web hosts. It’s commonly found near the top level of website files. Because the .htaccess filename begins with a period, you may need to enable the option to view hidden files to see it..htaccess file shown in FTP client.
  4. Right-click on the file and select Download. This is your backup copy.
  5. Right-click the file again and select Rename.
  6. Rename the file however you prefer. You might add the date for later reference.
  7. Test the website with the .htaccess file disabled. If it works, you’ll know there’s an issue with the .htaccess file.

While there are exceptions, many times if you delete or rename the .htaccess file, your web host automatically adds a new .htaccess file. The new file may contain only some of the original rules or be completely empty by default. You must examine your site’s .htaccess file for typos or misconfigurations. Try adding back any existing rules one by one to see which is causing the error.

Review CDN settings

If you use a Content Delivery Network (CDN), ensure it’s configured correctly. Errors in CDN settings can result in 502 errors. Depending on your CDN setup, try disabling the CDN temporarily to see if that fixes the issue.

502 bad gateway errors with Cloudflare

If your site uses Cloudflare and you see a message like 502 Bad Gateway Cloudflare, you can rest easy knowing it’s probably a Cloudflare issue. Check the status page for any existing outages or contact support for assistance.

Cloudflare's basic 502 bad gateway page.

In a second version, Cloudflare sites may display Error 502 bad gateway, and a graphic depicting an issue between Cloudflare and the site’s web host. In this case, it’s most likely an issue with your web host.

Cloudflare's error 502 page showing a problem between cloudflare service and the web host.

You can read more about Cloudflare 5xx errors in the article Troubleshooting Cloudflare 5XX errors.

Check for server-side firewalls

Improper firewall configuration can lead to 502 Bad Gateway errors. A firewall is a network security system that monitors and controls the incoming and outgoing network traffic based on predetermined security rules. It typically establishes a barrier between a trusted network and an untrusted network.

There can be cases in which some awkward firewall settings can consider safe and valid content malicious and, consequently, cut off traffic, which in turn causes 502 Bad Gateway errors. Check with your web hosting to ensure server-side firewalls are not mistakenly blocking legitimate requests. In this case, you may see an error message stating Hosting Server Read Timeout HTTP 502 – unable to connect to the origin server and depicting an issue between Cloudflare and your web host.

HTTP 502 timeout error between GoDaddy firewall and hosting.

Contact hosting provider

Contact your hosting provider for assistance if you cannot resolve the issue.


What is the difference between a 404 error and a 502?

A 404 Not Found error occurs when content can’t be found by the web server. A 502 Bad Gateway error happens when the proxy server can’t get any response or gets an invalid response from the upstream server. You come across 404 when requested content was removed or doesn’t exist. You see 502 errors when there is an issue with the upstream or origin server or a communication issue between proxy and upstream servers.

What is the difference between 502, 503, and 504 error messages on websites?

You got a 502 Bad Gateway error when the proxy server doesn’t get a valid response from the upstream or origin server. 504 Gateway Timeout error happens when the server which is acting as a proxy server can’t receive a timely response from the upstream server. 503 Service Unavailable error indicates that the server is not ready to handle the request, this happens when the server is down for maintenance or is overloaded.

Do 502 errors have any impact on website rankings?

The 502 Bad gateway error can have a major impact on website rankings. You don’t have to worry about a negative impact on SEO if the error lasts a few minutes. If the page is being crawled during this time, the crawler can load it from the cache. But you do need to worry if this error lasts for a few hours. In that case, Google will see the 502 error which can negatively impact your rankings.

What can I do when PHP is working in the command line but returns a 502 error in the browser?

502 error happens because of bad communication between proxy and upstream servers. When you’re running PHP in the command line you don’t need a web server, PHP works for you directly. To find out the reasons for 502 errors, read the above-described tips.

Despite their seemingly daunting nature, understanding 502 errors is the first step towards fixing them. Remember, while there are a few tricks you can try on your end—like refreshing the page, checking your internet connection, or switching browsers—the real fix usually lies with the website’s server or network.

So, the next time you encounter this error, take a breath, and try the basics, but be patient. You may have to wait until the website is accessible.

Now, we’re curious to hear from you! What’s your go-to move when you bump into a 502 Bad Gateway error? Do you have any personal tips or tricks up your sleeve? Let us know your experiences and strategies in the comments below.

Say goodbye to website errors

No more website errors with 10Web

Share article

Leave a comment

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

Your email address will never be published or shared. Required fields are marked *


Name *