One place for hosting & domains

      November 2022

      502 Bad Gateway Error: What It Is and How to Fix It

      If you run an online business, you’ll want your website to be available at all times. Unfortunately, WordPress problems like the 502 Bad Gateway error are common and can prevent users from accessing your site.

      The good news is that this error is relatively easy to fix. Once you’ve determined the cause, you can take the necessary steps to resolve the problem and make your website accessible again.

      In this post, we’ll take a closer look at the 502 Bad Gateway error message and its leading causes. Then, we’ll show you how to fix it. Let’s get started!

      What Is the 502 Bad Gateway Error?

      Whenever you try accessing a website, your browser sends a request to the site’s server. This server processes the request and returns the data (i.e., the site’s content).

      You’ll see an HTTP status code if something goes wrong during the process. Sometimes, this is accompanied by a message that describes the problem.

      A 502 Bad Gateway error indicates that the server received an invalid response from an inbound server and usually happens if the site is using a proxy or gateway server.

      The error message you see may vary, depending on your browser and the server you’re trying to access. However, typically you’ll receive one of the following alerts:

      • “502 Bad Gateway”
      • “502 Proxy Error”
      • “Error 502”
      • “HTTP Error 502 – Bad Gateway”
      • Temporary Error (502)
      • “502 Service Temporarily Overloaded”

      As you can see, the 502 status code may indicate an issue with the proxy server or a server overload. However, there are other possible causes of this error.

      What Causes the 502 Bad Gateway Error?

      Several issues can return a 502 Bad Gateway error. These include:

      • An unresolved domain name. The domain name might not be connecting to the correct IP address. This can happen because you’ve recently migrated your site to a new host, and the DNS servers haven’t yet finished propagating.
      • An over-sensitive firewall. If your site or your web host is using a firewall, it may be blocking certain internet providers or IP addresses. This happens when the firewall detects a false threat.
      • Server overload. The origin server may have crashed due to a sudden spike in traffic. This problem is more common if you’re on a shared hosting plan and your server has limited resources.

      It’s worth noting that the 502 Bad Gateway error doesn’t always indicate a problem with the server. It can also be caused by a client-side issue, like an outdated browser version or corrupted files in the browser cache.

      How Do You Fix the 502 Bad Gateway Error? (10 Possible Solutions)

      Now, let’s look at how to fix the 502 Bad Gateway error! We’ll cover two scenarios: an issue on the client side and a problem with the server.

      1. Refresh the Page and Try a Different Browser

      Let’s start with the simplest solution. The 502 Bad Gateway error could be a temporary issue. For example, the web server may have become overloaded for a few minutes or experienced a brief surge in traffic.

      Therefore, wait a few moments and reload the site. It’s also a good idea to try accessing the page on a different browser or device. This process will help you determine if it’s a client-side or server-side issue.

      Additionally, you could use a tool like Down for Everyone or Just Me, or Is It Down Right Now to confirm whether the problem is on your end or with the site’s host:

      The “Down for Everyone or Just Me” online tool

      If the results show that the site is up, you’ll need to try a few things on your browser and computer (which we’ll show you in the following steps). On the other hand, if the site is down for everyone, then you’ll have to go into your site’s back end to locate the problem — we’ll look into this later in the post.

      2. Clear Your Browser’s Cache

      Your browser might be storing outdated data for your site, which could lead to the Bad Gateway error. Alternatively, it may contain corrupted files that prevent access to your website.

      It’s a good idea to clear your browser cache. For example, in Google Chrome, click on the three dots in the top right-hand corner and select More tools > Clear browsing data.

      This will launch a popup window:

      Clearing the browser cache in Google Chrome

      Then, choose a time range, make sure the options for Cookies and other site data and Cached images and files are selected, and hit Clear data. Once complete, re-launch the browser and try accessing your site.

      The process for clearing cache in other browsers like Mozilla Firefox is similar. However, if this method doesn’t resolve the 502 gateway issue, you’ll need to move on to the next step.

      Get Content Delivered Straight to Your Inbox

      Subscribe to our blog and receive great content just like this delivered straight to your inbox.

      3. Flush the DNS Cache

      The 502 gateway error could also be caused by a Domain Name System (DNS) issue. For example, if you’ve just migrated your site to a new web host, the propagation process may take up to 48 hours.

      However, there might also be an issue with your local DNS cache. This temporary storage on your device contains information about visited domain names.

      To flush the DNS cache in Windows, press the Windows key, then type in “CMD” and hit Enter:

      Launching the Command Prompt in Windows

      This will bring up the Command Prompt window:

      The Command Prompt Window

      Here, you’ll need to type in the following command:

      ipconfig /flushdns

      When it’s ready, you should see a message that says, “Successfully flushed the DNS resolver Cache”.

      If you have a macOS device, you’ll need to enter the following command in the terminal:

      dscacheutil -flushcache

      Alternatively, you could temporarily change your DNS server to a third-party service, such as Google Public DNS.

      4. Check Your Site’s Error Log

      If your site is down for everyone and the problem is not with your device, you may want to check your error logs. These can help you identify what caused the issue. For example, a plugin conflict or update may have triggered the 502 Bad Gateway error.

      You’ll need to access your site’s files to view these logs. You can do this via the File Manager in your hosting account or a Secure File Transfer Protocol (SFTP) client like FileZilla.

      If you’re a DreamHost customer, log in to your account and navigate to Websites > Manage Websites. Select your site, then navigate to Manage Files and click on Manage:

      The DreamHost hosting account

      This will launch the File Manager. Click on the folder that contains your domain name, and look for wp-content:

      Open the folder and locate a file called debug.log:

      The debug.log file in the File Manager

      Look for the last logged error. It might give you clues as to what has gone wrong. You can then take steps to resolve the issue. For example, you might need to disable a plugin. (We’ll show you how in the next section).

      The process is almost identical if you use an SFTP client or a different hosting account. You can look for a file called error_log (or something similar) in your wp-content folder.

      5. Deactivate Your Plugins and Themes

      If you’ve installed a new plugin or theme, it might conflict with another tool on your site, prompting a 502 gateway error. A recent plugin update might also cause this.

      Since you cannot access your WordPress dashboard, you’ll need to deactivate your plugins and themes from the File Manager in your hosting account. Alternatively, you could use an SFTP client.

      If you’re a DreamHost user, log in to your account and open your site’s File Manager (as shown in the previous step). Then, go to wp-content and look for a folder called plugins:

      The plugins folder in the File Manager

      To deactivate your plugins, all you need to do is rename this folder. However, if you already know which plugin is causing trouble, you can locate it inside the plugins folder and rename its folder instead.

      You can now try accessing your site again. If it’s up and running, log in to the WordPress dashboard and re-activate each plugin one by one while refreshing the page. This process will help you identify the culprit.

      If you know which plugin is causing the 502 gateway error, we recommend removing it from your site or disabling it until the developers release a fix. You’ll just need to repeat the same process to deactivate your themes.

      Don’t worry if you’re still having issues after deactivating your plugins and themes— there are still a couple more things you can try.

      6. Disable Your CDN or Firewall

      The 502 gateway error could also be caused by your Content Delivery Network (CDN) or firewall. If you’re using Cloudflare, you can simply check to see if there are any reported issues.

      For example, the server might be undergoing scheduled maintenance:

      The Cloudflare System Status page

      Alternatively, try disabling the CDN to see if it resolves the issue. If you’re using a firewall, you might also want to deactivate it.

      You should be able to manage your CDN and firewall from your hosting account dashboard. If you’re unsure where to find these settings, we recommend contacting your web host for assistance.

      7. Restart PHP and Increase Your PHP Limits

      The 502 gateway error could also be caused by a PHP timeout issue. This happens when the PHP process takes longer than the maximum load time and the request times out.

      First, you might want to try restarting PHP. This could help resolve any connectivity issues. If this option is unavailable in your hosting dashboard, you might want to ask your web host to do it for you.

      Alternatively, you might need to change your server’s max_execution_time or max_input_time values. By default, these are set to 300 seconds. However, you can ask your web host to increase these values.

      8. Contact Your Hosting Provider

      If none of the above steps help solve your problem, you should consider contacting your hosting provider. They might be experiencing a server issue that’s affecting your site. If that’s the cause, there’s nothing you can do but wait.

      Additionally, they might be able to identify the source of the 502 gateway error and walk you through a solution. Most web hosts offer 24/7 support, so they should be able to resolve the issue quickly!

      Solve the 502 Bad Gateway Error

      The 502 gateway error is usually caused by an issue with the server. For instance, it might have experienced a spike in traffic that affected its performance and availability. However, this error could also be triggered by plugin conflicts and updates.

      To troubleshoot the problem, start by clearing your browser cache and local DNS cache to rule out any issues on your end. Then, you can try disabling your plugins, themes, CDN, and firewall. If you’re still experiencing problems, consider contacting your hosting provider for assistance.

      At DreamHost, our WordPress hosting plans come with 24/7 ticket support and live chat support. Our team of experts can help you resolve technical problems and get your site up and running again. Learn more about our plans!

      Do More with DreamPress

      DreamPress Plus and Pro users get access to Jetpack Professional (and 200+ premium themes) at no added cost!

      Managed WordPress Hosting - DreamPress

      Source link

      How to Upgrade to Ubuntu 22.04 LTS

      Although Ubuntu 20.04 LTS (Long Term Support) is still supported, users should upgrade Ubuntu to the more recent 22.04 LTS. Upgrading to the new release ensures the system can access the most recent security upgrades and application packages. This guide describes how to perform an inline upgrade from Ubuntu 20.xx or 21.xx to 22.04.

      New Features in Ubuntu 22.04

      Ubuntu 22.04 LTS from Canonical is also referred to as “Jammy Jellyfish”. Ubuntu generally supports their LTS releases for five years, which means Ubuntu 22.04 is supported until April 2027. This is superior to the Ubuntu 20.04 schedule, where support ends in April 2025. In addition, most application developers test their programs more thoroughly against the latest LTS release.

      In addition to the longer support period, Ubuntu 22.04 includes these other features and improvements:

      • Enhanced performance and better power efficiency.
      • A better display, featuring double the frame rate.
      • New power management options.
      • Updated security patches.
      • GNOME 42, which includes a streamlined user interface, on-screen notifications, and better multi-monitor support.
      • Increased customization options.
      • Firefox availability through a Snap package.
      • New releases of applications and toolchains. Updates and enhancements are available for Apache, MySQL, Perl, PHP, PostgreSQL, Python, and Ruby.
      • A new version (5.15) of the Linux Kernel.

      Inline Upgrade versus Clean Install

      There are two ways to upgrade a node. These are the inline upgrade method and the clean install approach. This guide only explains how to perform an inline upgrade. However, it is important to understand both methods to make an informed choice.

      The Inline Upgrade Method

      In an inline upgrade, the primary node is upgraded in place using either the GUI or command line directives. Ubuntu downloads and installs the new release of the operating system on the same system. The files and applications on the system are left unchanged and the node can immediately resume operations after the upgrade. Some of the advantages and disadvantages of this method, and other factors to consider, are as follows:

      • This is the easiest and fastest method of upgrading a node. Depending on the size of the new release, the node might be fully operational in as little as 15 minutes.
      • The Ubuntu upgrade procedure is well tested and generally reliable.
      • Users do not have to remember to reinstall a critical program or import data from the original node.
      • It is impossible to avoid some downtime while the updates are installed and the system reboots and initializes. During this period, any websites or applications hosted on the node are inaccessible. It is crucial to declare a maintenance window or switch to a backup system for the duration of the upgrade.
      • There is a greater chance of complications. Some applications might not work properly after the upgrade and might have to be reinstalled. There is also a greater chance of data corruption.
      • This method of upgrading tends to retain “digital residue”. This includes unnecessary or outdated packages, patches, and data.
      • This method is recommended if the system is only one release behind and is mainly running a widely used and tested configuration such as a LAMP stack. An inline upgrade might run into more problems when the system configuration is complicated or includes in-house applications.


      Although this process upgrades the Ubuntu operating system and most common programs, it does not necessarily upgrade every application. It is difficult to predict how the upgrade might affect these programs.

      The Clean Install Method

      The clean install method takes the opposite approach to the inline upgrade. This approach deploys a brand new Linode running the Ubuntu 22.04 release. All necessary applications are reinstalled and the backed-up data from the old node is copied over. After the new node is fully configured and operational, the old node is decommissioned.

      The pros and cons of a clean install are as follows:

      • It is easier to troubleshoot any problems because there are fewer dependencies.
      • The configuration tends to be cleaner. Old packages and unwanted files are not copied over.
      • This method takes a lot more effort and is more error prone. It is easy to forget to port over important applications and application data.
      • This method is a better choice if the system is running a much older release of Ubuntu or if the configuration is very convoluted. It is also a good choice for systems under the control of an Infrastructure as Code (IaC) application, like Terraform or Chef. These applications allow administrators to automatically provision a new remote node with a standard configuration.

      For an in-depth explanation of the clean install method, see the
      Linode guide to manually upgrading a node.

      Before You Begin

      1. If you have not already done so, create a Linode account and Compute Instance. See our
        Getting Started with Linode and
        Creating a Compute Instance guides.

      2. Follow our
        Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access.

      3. Ensure there is at least 20 GB of disk space available. Verify the amount of disk space availability using the df -Th command.


      This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you are not familiar with the sudo command, see the
      Users and Groups guide.

      How to Upgrade to Ubuntu 22.04 LTS

      This guide is designed for users who want to upgrade from Ubuntu 20.04 LTS to Ubuntu 22.04 LTS. However, it is generally applicable for upgrades to Ubuntu 22.04 from any release of Ubuntu 20.xx or 21.xx.

      If the Linode is running Ubuntu 18.xx or any earlier release, first upgrade it to Ubuntu 20.04 LTS. Then perform the steps in this guide to upgrade from Ubuntu 20.04 LTS to the 22.04 LTS. See the
      Linode guide to Upgrade to Ubuntu 20.04 for more information. Alternatively, if the Ubuntu software and applications are very old, it might make more sense to perform a clean install instead.


      This operation cannot be canceled after it is started. Ensure there is a stable connection to the Linode and backup power is available.

      How to Prepare the Linode for the Upgrade

      To increase the chance of a successful upgrade, ensure the operating system and all applications are up to date. All data should be backed up and active user applications shut down.

      To prepare the Ubuntu system for the upgrade, follow these steps.

      1. Upgrade the Linode and ensure it is up to date.

        sudo apt update -y && sudo apt upgrade -y && sudo apt dist-upgrade -y
      2. To simplify the upgrade, remove unused packages and files.

        sudo apt autoremove -y && sudo apt autoclean -y
      3. Reboot the node to ensure any new kernel upgrades are installed. Linode makes new kernels available through the Linode cloud manager. Any updates are automatically applied to the node upon a reboot. For more information, see the
        Linode guide to monitoring and maintaining a system.

      4. Make a backup copy of the system configuration and all application data. The easiest way to do this is to back up the entire system. Subscribing to the
        Linode Backup Service allows you to take a manual snapshot before the upgrade.

      5. Stop as many non-critical user applications services as possible, including web and database servers. Focus on applications that might be subject to data corruption. To see a list of the active services, use the command systemctl | grep running.

        sudo systemctl | grep running
        apache2.service loaded active running The Apache HTTP Server
        mysql.service loaded active running MySQL Community Server
      6. Use the command sudo systemctl stop <application_name> to stop a service. The following example demonstrates how to stop the Apache web server instance.


        Do not stop any essential system services such as ssh or any systemd entry.

        sudo systemctl stop apache2
      7. Allow connections on TCP port 1022 through the ufw firewall. This permits Ubuntu to use a fallback port if the main connection drops. After adding the rule, reload the firewall.

        sudo ufw allow 1022/tcp
        sudo ufw reload
        Firewall reloaded
      8. Confirm connections on TCP port 1022 are now allowed.

        Status: active
        To                         Action      From
        --                         ------      ----
        OpenSSH                    ALLOW       Anywhere
        Apache Full                ALLOW       Anywhere
        1022/tcp                   ALLOW       Anywhere
        OpenSSH (v6)               ALLOW       Anywhere (v6)
        Apache Full (v6)           ALLOW       Anywhere (v6)
        1022/tcp (v6)              ALLOW       Anywhere (v6)

      How to Install Ubuntu Release 22.04

      The node is now ready for the upgrade. Ensure the update manager is installed, then initiate the upgrade. The upgrade might take some time, depending on the configuration, and must not be interrupted. Ensure there is enough time to complete the entire upgrade before proceeding.


      The upgrade operation can be performed using either a LISH session or an SSH connection. A LISH session is safer, but if SSH is used, the upgrade manager opens a second port for redundancy. This guide uses SSH for the procedure to demonstrate the additional steps required.

      1. Ensure the update-manager-core package is installed. On many systems, this package might already be available.

        sudo apt install update-manager-core
      2. Confirm the release-upgrader is set to the correct release update mode. The file /etc/update-manager/release-upgrades must include the line Prompt=lts.

        sudo cat /etc/update-manager/release-upgrades
        File: /etc/update-manager/release-upgrades
        # Default behavior for the release upgrader.
        # Default prompting and upgrade behavior, valid options:
        #  never  - Never check for, or allow upgrading to, a new release.
        #  normal - Check to see if a new release is available.  If more than one new
        #           release is found, the release upgrader will attempt to upgrade to
        #           the supported release that immediately succeeds the
        #           currently-running release.
        #  lts    - Check to see if a new LTS release is available.  The upgrader
        #           will attempt to upgrade to the first LTS release available after
        #           the currently-running one.  Note that if this option is used and
        #           the currently-running release is not itself an LTS release the
        #           upgrader will assume prompt was meant to be normal.
      3. Run the do-release-upgrade command to start the upgrade.


        To force an upgrade from the latest supported release to a development release, use the command do-release-upgrade -d. This guide focuses on upgrading to the latest supported release and does not use this flag.

      4. If the operation is performed using a SSH connection, Ubuntu verifies the SSH connection details and asks whether to continue. Answer y to continue.

        Continue running under SSH?
        This session appears to be running under ssh. It is not recommended
        to perform a upgrade over ssh currently because in case of failure it
        is harder to recover.
        If you continue, an additional ssh daemon will be started at port
        Do you want to continue?
      5. Ubuntu asks the user to confirm the new SSH port is allowed through the firewall. The port should already be open. Press the Enter key to continue.

        Starting additional sshd
        To make recovery in case of failure easier, an additional sshd will
        be started on port '1022'. If anything goes wrong with the running
        ssh you can still connect to the additional one.
        If you run a firewall, you may need to temporarily open this port. As
        this is potentially dangerous it's not done automatically. You can
        open the port with e.g.:
        'iptables -I INPUT -p tcp --dport 1022 -j ACCEPT'
        To continue please press [ENTER]
      6. Ubuntu reads through the list of packages, builds the dependencies, and searches for internal package mirrors. If no mirrors are available, it prompts for approval to rewrite the sources.list file. Enter y to continue.

        Fetched 336 kB in 0s (0 B/s)
        Reading package lists... Done
        No valid mirror found
        While scanning your repository information no mirror entry for the
        upgrade was found. This can happen if you run an internal mirror or
        if the mirror information is out of date.
        Do you want to rewrite your 'sources.list' file anyway? If you choose
        'Yes' here it will update all 'focal' to 'jammy' entries.
        If you select 'No' the upgrade will cancel.
        Continue [yN]
      7. Ubuntu downloads the new packages and files. It determines which packages are no longer supported and requests approval to proceed. It also calculates how long the upgrade might take. To continue with the upgrade, answer y.


        To see details about the packages to be removed, installed, and upgraded, enter d. Enter q to exit the details screen. Then enter y to continue with the upgrade.

        Do you want to start the upgrade?
        14 installed packages are no longer supported by Canonical. You can
        still get support from the community.
        5 packages are going to be removed. 91 new packages are going to be
        installed. 571 packages are going to be upgraded.
        You have to download a total of 552 M. This download will take about
        2 minutes with you connection.
        Installing the upgrade can take several hours. Once the download has
        finished, the process cannot be canceled.
        Continue [yN]  Details [d]
      8. Ubuntu displays a pop-up asking whether to restart the services after the upgrade. Select either the <Yes> button to automatically restart them or <No> to restart them manually.

        Ubuntu Services Pop-up

      9. Ubuntu continues downloading the new packages. This can take a considerable length of time, especially if many applications have been installed. However, Ubuntu echoes the package names when it installs and processes them, allowing users to monitor the progress. During the upgrade, Ubuntu uses a pop-up to ask users how to handle the sshd_config file. Select the keep the local version currently installed option, and then choose <OK>.

        Ubuntu SSH Configuration Pop-up

      10. Ubuntu locates any obsolete packages and asks the user whether to remove them. Enter y to delete the outdated packages.

        Searching for obsolete software
        Reading state information... Done
        Remove obsolete packages?
        41 packages are going to be removed.
        Continue [yN]  Details [d]
      11. Ubuntu removes the packages and finalizes the upgrade. This stage might also take some length of time. Ubuntu informs the user that the upgrade is complete and prompts them to reboot the system. Select y to reboot and finalize the upgrade.

        System upgrade is complete.
        Restart required
        To finish the upgrade, a restart is required.
        If you select 'y' the system will be restarted.
        Continue [yN]

      How to Perform Post-Upgrade Clean-Up Activities

      Ubuntu has now been upgraded to version 22.04 LTS. After the Linode reboots, it is ready to resume operations. However, it is important to validate the upgrade. There are also still a few security concerns to fix and clean-up activities to perform. Log in to the Linode and perform the following steps.

      1. Use the lsb_release -a command to verify the correct release of Ubuntu is now installed. The Release attribute should be 22.04.

        No LSB modules are available.
        Distributor ID: Ubuntu
        Description:    Ubuntu 22.04.1 LTS
        Release:        22.04
        Codename:       jammy
      2. Optional: To validate the kernel version, use the uname command.

        Linux 5.15.0-53-generic x86_64
      3. To increase security, close port 1022 in the ufw firewall. Reload the firewall.

        sudo ufw delete allow 1022/tcp
        sudo ufw reload
      4. Confirm the firewall rules are updated.

        Status: active
        To                         Action      From
        --                         ------      ----
        OpenSSH                    ALLOW       Anywhere
        Apache Full                ALLOW       Anywhere
        OpenSSH (v6)               ALLOW       Anywhere (v6)
        Apache Full (v6)           ALLOW       Anywhere (v6)
      5. Ubuntu disables any third-party repositories during the upgrade. To search for disabled repositories, switch to the sources.list.d directory and list the entries.

        cd /etc/apt/sources.list.d
        ls -l
      6. Edit each list using a text editor. Remove the # symbol at the start of the affected entries, and save the file. In the following example, remove the # symbol in front of deb [arch=amd64].

        nano archive-application.list
        File: archive-application.list
        deb [arch=amd64] jammy main
      7. Update any third-party repositories and remove unnecessary packages using apt commands.

        sudo apt update -y && sudo apt upgrade -y && sudo apt dist-upgrade -y && sudo apt autoremove -y && sudo apt autoclean -y


      Users can access security updates and new features by upgrading to the new Ubuntu 22.04 LTS release. The two methods of updating a Linode are the inline update or the clean install. This guide explains how to perform an Ubuntu inline upgrade, which is the quickest and easiest method.

      To prepare to upgrade a Linode to Ubuntu 22.04 LTS, update and upgrade the node, back up the data, and stop all services. Use the do-release-upgrade command to initiate the upgrade and follow all Ubuntu prompts. After the upgrade, tighten up security, enable third-party archives, and perform some clean-up tasks. For more information about the Ubuntu 22.04 LTS release, see the
      Ubuntu server documentation.

      More Information

      You may wish to consult the following resources for additional information
      on this topic. While these are provided in the hope that they will be
      useful, please note that we cannot vouch for the accuracy or timeliness of
      externally hosted materials.

      Source link