Ошибка 502 Bad Gateway не зависит от локальных настроек вашего сайта и может обнаружиться на любом устройстве, в любом браузере и операционной системе. Причины появления этой ошибки нелегко идентифицируются и исправляются, в основном, со стороны сервера.
Ошибка 502 генерируется сервером и сигнализирует, что запрос для страницы, сценария или процесса занял слишком много времени для завершения и был принудительно отменен. Главная причина ошибки 502 заключается в нехватке ресурсов на сервере – у PHP-движка закончилась память. Для сайтов на WordPress ошибка появляется при обновлении движка и плагинов или при сохранении больших записей. Это может происходить из-за следующих проблем:
- Очень большой код – много установленных плагинов или очень сложных модулей;
- Чересчур много посетителей на сайте;
- Малое время выполнения скриптов.
Сервера обычно справляются с большим использованием памяти при сотнях одновременных посещений сайта, но в исключительных случаях одновременная загрузка большого количества может вызвать ошибку 502.
Как устранить ошибку WordPress 502 bad gateway
Поскольку ошибка 502 Bad Gateway напрямую связана с серверной проблемой, попробуйте выполнить следующие шаги для разрешения ситуации.
- Повторите заход на сайт. Используйте кнопку обновления в браузере или нажмите F5, чтобы перезагрузить страницу. Повторная загрузка сайта часто проходит без ошибок.
- Вернитесь к сайту позже. Ошибка 502 Bad Gateway может оказаться временной на ресурсе, к которому вы обращаетесь.
- Попробуйте почистить кэш браузера. Поврежденные или устаревшие файлы, которые сохраняются браузером, могут провоцировать эту проблему.
- Свяжитесь с вашим хостинг-провайдером, чтобы прояснить ситуацию.
Если компьютер и сеть работают нормально, а интернет-ресурс показывает ошибку 502, это может быть из-за проблемы с хостингом. Уточните у техподдержки допустимое количество оперативной памяти на вашем тарифе хостинга, при необходимости может потребоваться его увеличить. Попросите также увеличить время выполнения скриптов. В случае регулярных ошибок стоит сменить хостинг-провайдера.
WordPress потребляет большое количество ресурсов сервера, особенно если вы используете множество плагинов. Чтобы проверить, вписываетесь ли вы в установленный тариф, в админке зайдите в меню «Внешний вид — Редактор», из списка шаблонов выберите шаблон подвала (файл footer.php) и добавьте туда строку кода:
<?php include('adplus-right-bottom.html'); ?>
В результате на странице будет выведено количество запросов, время на их обработку и размер затраченной памяти. Если эти числа достигают ограничений, предусмотренных хостером, следует задуматься об оптимизации кода на сайте или расширении объема оперативной памяти на сервере, если это возможно.
iPipe – надёжный хостинг-провайдер с опытом работы более 15 лет.
Мы предлагаем:
- Виртуальные серверы с NVMe SSD дисками от 299 руб/мес
- Безлимитный хостинг на SSD дисках от 142 руб/мес
- Выделенные серверы в наличии и под заказ
- Регистрацию доменов в более 350 зонах
WordPress is easy, but it is equally frustrating to troubleshoot the errors that can occur at any time. Just like prescribing the right medicine to fight disease effectively, you need complete knowledge about that disease. Knowing the error and its causes are essential before troubleshooting it.
When your website has the 502 Bad Gateway Error, it’s like solving a mystery. You don’t know what exactly happened or why you expect that something is wrong, and you need to fix it. In this article, I’ll tell you about the 502 Bad Gateway Error and how you can fix it in your WordPress.
- What Is the 502 Bad Gateway Error?
- Why Does 502 Bad Gateway Error Occur?
- How Does 502 Bad Gateway Affect the SEO
- Fix the “502 Bad Gateway” Error in WordPress
What Is the 502 Bad Gateway Error?
To understand the 502 Bad Gateway Error, you should know how a browser loads data from the server. When a user visits a website, the server sends a request to fetch the data required to display the content in the browser.
If the server responds accurately to the requests, it receives the requested content. Otherwise, the 502 Bad Gateway Error screen comes up.
WordPress websites run on multiple servers allocated to a specific task. For example:
- Database server for WordPress databases,
- Application server to run PHP and other app-related content,
- The reversed proxy server responsible for Nginx, Apache, Varnish,
- Web server to serve website files.
The multiple servers together can complicate the way the browser handles the requests. Upon receiving the request, the reversed proxy server fetches data from origin servers like a database server, application server, and web server.
If any of these servers send an invalid response, the reversed proxy server returns to the browser and displays a 502 Bad Gateway Error.
We often see 502 Bad Gateway Error differently on different websites, but they all point to the same: the server could not respond to the requests. Let us look at some of the examples this error shows.
- “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.”
Twitter displays 502 Bad Gateway Error in a friendlier way.
Google displays a 502 Bad Gateway Error with the suggestion of trying again after some time.
Now that we have understood what is 502 Bad Gateway Error is and how different websites display it. Let us move ahead and explore what causes this error and how can we fix it in WordPress?
Why Does 502 Bad Gateway Error Occur in WordPress?
We get a 502 Bad Gateway Error when the server fails to respond accurately and returns the request with invalid information. However, there are other possibilities as well, and knowing them is crucial if you wish to troubleshoot this error effectively.
- Your server is busy with other tasks or hit by traffic spikes
- Origin servers are unresponsive or inaccessible
- Errors in the database
- Problem with the reverse proxy server
- Corrupt PHP scripts in WordPress files
- WordPress CDN is acting up
- DNS issues
All of the above possibilities can result in WordPress 502 Bad Gateway Error. However, troubleshooting any error gets trickier if you do not know the elements involved in triggering that error.
How Does 502 Bad Gateway Affect the SEO
If your site often goes down because of the 502 Bad Gateway error, it will also affect your site’s traffic. Imagine your visitor gets this error on your site; he might not visit your site next time. Similarly, it will impact the crawling and indexing of your site due to unavailability. Hence, you will lose your organic ranking and traffic.
These are the easiest methods to fix the 502 Bad Gateway Error in WordPress.
- Check Hosting Server
- Reload Web Page
- Clear Browser Cache
- Check DNS Issues
- Clear DNS Cache
- Disable CDN/Firewall
- Audit Themes/Plugins
- Check Error Logs
- Set PHP Timeout
- Check Custom Scripts
1. Check Hosting Server
The first thing you need is to check if your web server is responsive or not. It is not always something terrible happening to your WordPress website. The easiest way to determine if your server is the culprit is to run an online scan. Visit site24x7 and enter your site URL.
The multiple locations will ping your server and show you the stats like Load time, Package Loss, and Response time.
Another way to check your web server’s responsiveness is to ping it manually using SSH. Simply access the SSH terminal and run the following command:
ping (server IP)
Now, replace “server IP” with your server IP address.
If your server is responsive, it will show the ping on each interval.
Sometimes any query or task takes more time than usual; the server cancels it and returns with a 502 Bad Gateway Error. It is common in shared hosting, and the provider kills the script to avoid any negative impact on other websites hosted on the same server.
If you are using Cloudways, you will have a low chance of getting this error. That is because you are the only owner of your server and control the websites hosted on it, and we use a powerful stack that can cope with a load on servers.
However, if you still encounter such issues, Cloudways’ 24/7 live chat support can help you recover from this situation.
2. Reload Web Page
Sometimes just by reloading the web page, you can save hours’ worth of troubleshooting. It is possible that you get an overloaded server for some time and when you check back in a minute or so, it brings back on.
Also, confirm if the website is down for you or everyone else. Test the URL on Down for Everyone or Just Me to do this.
If the website is up for everyone else, then the problem is at your end. Try switching the web browser.
3. Clear Browser Cache
The browser caches or stores site data so the next time the user visits, it does not have to repeatedly download the same static content. It is an effective way of utilizing resources but has some drawbacks.
Let’s say you went to a different browser and the web page loaded just fine. Knowing that your web page loads correctly, you return to your default browser, but the issue persists. That is because your browser displays the cached copy of that web page. To fix that, clear your browser cache via Ctrl+Shift+Del (for Windows) or Shift+Cmd+Del (for Mac).
4. Check DNS Issues
A Domain Name System (DNS) is a way of linking a domain name with an IP address. If the domain fails to resolve to the correct IP, it can trigger a 502 Bad Gateway Error. It commonly occurs while migrating a WordPress site to a new host that requires changes in the DNS name server.
The DNS changes can take between 24 to 36 hours to propagate. If you try to access your site during this period, you might get a WordPress 502 Bad Gateway Error.
5. Clear DNS Cache
You can clear the DNS cache from Windows Command Prompt. In Windows, run ipconfig/flushdns command to clear the DNS cache. In Mac, run the command as dscacheutil -flushcache inside the terminal window.
6. Disable CDN/Firewall
If you use a CDN service or a firewall on your website, their servers may be acting up.
A CDN serves static website content and loads your site to a global audience faster. In contrast, a firewall protects your site against DDoS and other online attacks. However, A CDN/firewall can be one of the reasons for the 502 Bad Gateway Error in WordPress due to an extra layer between the server and browser.
To cross this from your list of possible causes, simply disable your CDN/firewall and then try to access your website. If the website loads correctly, then you have caught the culprit. You just need to contact CDN/firewall service provider to get it fixed.
7. Audit Themes/Plugins
A fully functional WordPress site is nearly impossible without adding themes and plugins. But they can also become one of the reasons for the 502 Bad Gateway Error. The problem lessens with the best wordpress plugins, but the threat of 502 error lurks with them as well. If they are not well-written, they can cause issues with your web server or take too long to process the requests. The problem can arise even if you work with the best wordpress themes for your website.
Start by deactivating all the plugins from FTP. Simply access your root directory where your WordPress files are installed, i.e., public_html folder, navigate to wp-content → plugins, and rename the plugins folder so it will become inaccessible to your site.
Now check your website to see if it loads correctly, then you can start activating plugins one by one until you find the one causing 502 Bad Gateway Error.
Look for a defective theme if you don’t find any faulty plugins. Go to your wp-content folder, navigate to themes and rename your activated theme to deactivate it. But remember, removing your theme might not be suitable as uploading it again can lose custom styling.
In the next step, refresh your website and if you see a white screen instead of an error, then your theme was causing the issue. Log in to your wp-admin and activate the default WordPress theme.
8. Check Error Logs
WordPress logs are useful when it comes to troubleshooting errors. You can enable the error logs by adding the following code inside the wp-config.php file.
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false );
The logs are located inside the wp-content folder. If you’re a Cloudways user, you can take advantage of the integrated monitoring tool New Relic for precise and comprehensive analysis.
9. Set PHP Timeout
When PHP reaches the maximum time in server configuration to execute a script, it shows an error. It can sometimes trigger WordPress 502 Bad Gateway Error. To avoid this, simply increase the maximum execution time value. It is set to 300 seconds by default, which is 5 minutes.
10. Check Custom Scripts
We create custom functionality and themes in WordPress. Sometimes, our web server doesn’t process these custom functionalities. Also, calling third-party APIs, such as Google reCAPTCHA, which generates long tokens, can stress the server and show the 502 Bad Gateway Error.
Summary
After reading this article, I hope 502 Bad Gateway Error will not look so scary the next time you see it. The troubleshooting is easy if you can predict the source and use the techniques listed in this article to fix it.
You can still fix the WordPress 502 Bad Gateway Error just by reloading and clearing the browser cache but not every day is sunny, so it is wise to prepare for the dark.
Frequently Asked Questions
Q: What causes a 502 Bad Gateway Error?
A: When you get an invalid response on your browser when trying to visit your site causes the 502 Bad Gateway Error.
Q: How do I fix Google 502 error?
A: You can fix the 502 Bad Gateway Error by following these methods:
- Check Hosting Server
- Reload Web Page
- Clear Browser Cache
- Check DNS Issues
- Clear DNS Cache
- Disable CDN/Firewall
- Audit Themes/Plugins
- Check Error Logs
- Set PHP Timeout
- Check Custom Scripts
Q: Is 502 Bad Gateway a virus?
A: No, it’s not a virus. You get the 502 error because of the bugs in your PHP. Server configuration or network error among servers can cause 502 Bad Gateway.
Share your opinion in the comment section.
COMMENT NOW
Share This Article
Customer Review at
“Beautifully optimized hosting for WordPress and Magento”
Arda Burak [Agency Owner]
Ibad Ur Rehman
Ibad Ur Rehman is a WordPress Community Manager at Cloudways. He likes to explore the latest open-source technologies and to interact with different communities. In his free time, he likes to read, watch a series or fly his favorite Cessna 172SP in X Plane 11 flight simulator.
Are you trying to resolve the 502 bad gateway error in WordPress?
When it comes to WordPress, there are a lot of different errors that can be downright frustrating and confusing. A few that come to mind are the Missing a Temporary Folder Error or the 400 Bad Request Error.
The 502 bad gateway error, however, is even more popular and concerns all the internet, not only WordPress.
Because it can be caused by so many different things, this error can be time-consuming to troubleshoot.
Here, I will guide you through the steps to fix the 502 bad gateways error in WordPress.
Table of contents
- What is a 502 Bad Gateway Error?
- Why Does the 502 Bad Gateway Happen?
- Fixing the 502 Bad Gateway Error in WordPress
- Step 1: Reload Your WordPress Website
- Step 2: Clear Your Browser Cache
- Step 3: DNS Issue
- Step 4: Disable the CDN or Firewall
- Step 5: Update Your Plugins and Themes
- Step 6: Check With Your Hosting Server
- Step 1: Reload Your WordPress Website
What is a 502 Bad Gateway Error?
This error code explains that the client received an invalid response from an inbound server: when the requested page cannot be delivered by your WordPress hosting server, it triggers a 502 bad gateway error.
Your browser sends a request to a web server whenever you visit a website. Upon receiving a request, the web server processes it, and then sends back the requested resources along with an HTTP header & status code.
Usually, an HTTP status code isn’t displayed unless there’s a problem. In essence, it is the server’s way of notifying you that something went wrong, plus instructions on how to correct it.
Many different types of 500 status errors exist (500, 501, 502, 503, 504, etc.) and each with a different meaning but they all fall into the same category: 500 error codes mean that the request was accepted by the server, but the request could not be fulfilled.
A 502 bad gateway error can appear in a variety of ways depending on the browser, web server, and operating system:
- “502 Bad Gateway”
- “Error 502”
- “HTTP Error 502 – Bad Gateway”
- “502 Service Temporarily Overloaded”
- “502 Proxy Error”
- “502 Server Error: The server encountered a temporary error and could not complete your request”
- “HTTP 502”
- Temporary Error (502)
- 502. That’s an error
- 502 bad gateway Cloudflare
- Bad Gateway: The proxy server received an invalid response from an upstream server
However, they all refer to the same thing.
Why Does the 502 Bad Gateway Happen?
Usually, 502 bad gateway errors occur when your request takes too long to be processed by the server. High traffic can cause a temporary glitch to cause this delay. A poorly coded WordPress theme or plugin could also be to blame. Furthermore, it can also be caused by server misconfiguration.
Fixing the 502 Bad Gateway Error in WordPress
Usually, this error is triggered when the server can’t find the reason for the invalid response. In practice, this means we will attempt different troubleshooting techniques until we find the problem.
Step 1: Reload Your WordPress Website
Due to increased traffic or low server resources, your server may sometimes take longer to respond. Usually, the problem will resolve itself in a few minutes. Reload the web page you are viewing to see if that was the cause of the problem.
In that case, you do not need to continue reading. However, If you encounter this error often, I invite you to keep reading since there may be something else to look at.
Step 2: Clear Your Browser Cache
Although the issue has been fixed, you will still see the 502 error because the browser is loading your website from the cache.
To fix this, just refresh your browser’s cache.
Step 3: DNS Issue
It is also possible for a 502 gateway error to originate from a DNS issue, such as a domain not resolving to the correct IP address or an inactive DNS server.
You should wait for things to propagate fully after migrating a WordPress site to a new host, which may take up to 24 hours in some cases.
Step 4: Disable the CDN or Firewall
A problem with your content delivery network (CDN) or firewall may also be to blame. The easiest way to troubleshoot this if you are using a 3rd-party CDN provider is to temporarily disable it.
It can also happen with providers who provide DDO-oS protection, such as Cloudflare. If you are having 502 errors with Cloudfare, please reach out to Cloudflare’s support.
Step 5: Update Your Plugins and Themes
Sometimes, scripts and queries are canceled by the server due to bad code in your WordPress site, possibly from a 3rd-party plugin or theme. The 502 error has also arisen from caching plugins that have been configured incorrectly. One way to troubleshoot this is by deactivating all your plugins.
Don’t worry, deactivating a plugin won’t erase your data.
A quick way to do this if you still have access to the admin interface is to browse to “Plugins” and click “Deactivate” from the bulk actions menu. It will disable all your plugins. This may fix the issue, but you’ll still have to find the culprit. Activate each one at a time, and reload the website after each activation. If you see the 502 gateway error, you’ve found the problem plugin.
To receive help, you can contact the plugin’s developer or submit a request in the WordPress support forum.
Alternatively, if you can’t access your admin, you can access your server via FTP and rename your plugins folder to something like plugins_debug. Check again your website. If it works, you will need to test each plugin individually.
Your plugin folder should now be named “plugins” again, then you should rename every plugin folder within it, one by one, until you find the guilty one.
Always ensure that your WordPress plugins, themes, and core are up-to-date. Additionally, verify that you’re running an up-to-date version of PHP.
Manage all your websites effortlessly
Automatic backups, comprehensive monitoring & much more
Try WP Umbrella
Step 6: Check With Your Hosting Server
When all the above troubleshooting steps fail, then it is likely that there is a problem with your hosting server.
The problem can be resolved by contacting your hosting company’s support team. You can tell them all the steps you’ve taken to troubleshoot the problem, it will help us to troubleshoot the issue more quickly.
An issue caused by a misconfigured server can usually be resolved quickly by all good WordPress service providers. If you are looking for an amazing WordPress provider, we recommend you to go to Kinsta.
That’s all. I hope this article helped you learn how to troubleshoot the 502 bad gateway error in WordPress.
In this article, we will explain one of the WordPress errors known as the 502 error code and will tell you how to fix 502 bad gateway error in WordPress. When it comes to a website (especially a WordPress one), there are always a lot of errors or different kinds of failures that can be frustrating.
You might probably encounter one of the WordPress common errors such as HTTP 404, HTTP 429 too many requests, or even this error: “upload filed to write file to disk”. Some of them can be fixed as easily as ABC, while other errors may be frightening (e.g. white screen of death).
In this article, we will speak about one of these errors known as the 502 error code. We will tell you how to fix 502 bad gateway errors in WordPress. But, before that, let’s start with its definition.
What is a 502 Bad Gateway Error?
To fix 502 bad gateway error in WordPress, first, you should know what the meaning of this code is, and when it happens. HTTP code 502 is a common error that happened when you are trying to visit a web page while the server gets an invalid response from another web server. In fact, this error is a server-side error and rarely caused by Wi-Fi connections or computers of users.
In fact, 502 bad gateway meaning is the error that is related to the server you are going to visit. This error is also known as 502 error code, HTTP 502 error, error reference number: 502, HTTP status code 502, and WordPress 502 error. Below is a list of different variations you might see on the web:
- “502 bad gateway”
- “Error 502”
- “HTTP 502”
- Temporary Error (502)
- “502 Proxy Error”
- That’s an Error
- “HTTP Error 502 – Bad Gateway”
- Bad Gateway: The Proxy server received an invalid response from an upstream server.
- 502 bad gateway Cloudflare
- “502 Service Temporary Overloaded”
- A blank white screen
- “502 Server Error: The server encountered a temporary error and could not complete your request”
Start Blogging
Self-host your WordPress on top-tier hardware, featuring NVMe storage and minimal latency around the world — choose your favorite distro.
Get WordPress VPS
Another variation can be: “502 – Web server received an invalid response while acting as a gateway or proxy server”. In this case, there is a problem with the page you are looking for, and can’t be displayed. In this error and HTTP status code 503, you can’t preciously tell what happened and what’s going wrong. But there are common issues that some of them will explain in the next paragraph.
Why does 502 Error happen?
Every time you visit a website, the browser will send a request to your web server. The web server receives all requests and starts processing them. Then, these requests will send back to the browsers along with HTTP status codes and an HTTP header. If the process goes wrong or any problem occurs, you can see these errors. In fact, these codes are the language of your server to notify you that something goes wrong.
As you probably know, there are different kinds of HTTP status codes (e.g. 500, 501, 502, 503, 520, etc.) that are different meanings, and 502 bad gateway meaning indicates that when a server acts as a gateway or a proxy, happening of this error will be probable. Below are three main issues that cause 502 bad gateway responses. These includes:
- Origin Server Down: in this situation, the server is not reachable. This may occur when the server is down or there is no connectivity to the server.
- Firewall Block Request: when the firewall blocks the communication between the main server and edge server, occurring this error will be probable. This can also occur by the security plugins of your content management system.
- Domain Name Not Resolvable: sometimes, the domain name is not resolving to the correct IP and it is important to note that DNS changes to a new server take some time to completely propagate and be active. So it may cause the 502 error in WordPress sites.
“Also read: How to Fix the HTTPS Not Secure Message in Chrome”
How 502 Errors Can Negatively Affect Your SEO?
You should hurry to fix 502 bad gateway error in WordPress because it negatively affects the SEO of your site. If your site remains down for only 10 minutes, the crawlers will simply deliver the page from the cache. You may also lose the chance of re-crawling.
If your site is down for an extended period of time (i.e. 6+ hours), then Google might see this error as a site-level issue that should be addressed. This problem can highly impact the ranking of your WordPress site. So, try to fix this problem as soon as possible.
15 Ways to Fix the 502 Bad Gateway Error?
Although facing an error in a WordPress site is frightening, you can simply fix the 502 bad gateway error most of the time with ease. In the following, we will provide you with a few solutions for fixing this error:
1. Try to Refresh the page
Bad gateway errors are automatically resolved themselves after some hours or even days! If you’ve got time, then sit back, stay relax and try again. However, if you want to fix the problem quickly, then reloading the page is a good idea. One tip for you to remember is once you meet an error in your browser, the first thing you should do is to refresh the page.
In case you’re on Windows and want to reload, try to press Ctrl + R, or if you’re on Mac, simply refresh by pressing Command + R. If you still have the issue with the 502 error, proceed to the next step.
2. Clear the cache
Once you refreshed the tab and nothing happened, it’s time to clear the browser’s cache.
Also Read: Clear DNS Cache – How to Flush DNS?
To do this is actually easy; all you need to do is to perform a hard refresh! You can also go in settings and manually delete the cache, but why do you want to go a long way? Do run a hard refresh, and yeah!
Windows users can press Ctrl+ Shift + F5 to do a hard reload. If you’re on Mac, then do Command + Shift + F5. Linux users only need to press F5 to do it.
Start Blogging
Self-host your WordPress on top-tier hardware, featuring NVMe storage and minimal latency around the world — choose your favorite distro.
Get WordPress VPS
3. Try incognito window
Browser extensions can sometimes cause problems. That’s why it’s recommended to disable some of them if you don’t use them at the moment. You might have lots of extensions, and disabling one by one can be boring! There’s even a percentage that the problem won’t get resolved by only disabling; removing them is also a problem because you may want to keep them always with you.
Nonetheless, try to go into incognito mode on your browser, so you don’t need to remove your extensions. Incognito mode also helps you exclude cookies, site data, and all other information that has been previously saved so that you’ll experience normal browsing.
4. Restart your device and network equipment
Temporary errors are also engaged here that may occur from time to time. You should reset not only your device but also your network equipment. This way, you’ll get rid of those temp things that come to you off and on.
5. Use another browser
Different browsers offer distinct features that work best for you on certain websites you use. It’s also advised to use Chrome or Firefox to check if your browser is corrupted. So, it makes good sense to change it right now!
6. Test on another device
Granted on specific terms, it’s apparent that you’d experience differently on different devices. This error is no exception. Try to load the website on another desktop or mobile browser, but keep in mind that you should also change the network, so there you go!
7. Check out the site status
Websites might momentarily get down for different purposes, and it’s sometimes out of any reason. To know if a website is down, check out Is It Down Right Now.
If none of the solutions above could fix the problem, move on steps below.
8. Look for Server Connectivity Issues
Most websites run on third-party hosting providers or multiple servers. If your server is down and your website shows your visitors this error, to fix 502 bad gateway error in WordPress you’d better wait for your server to finish maintenance or fix the problem causing the error.
Start Blogging
Self-host your WordPress on top-tier hardware, featuring NVMe storage and minimal latency around the world — choose your favorite distro.
Get WordPress VPS
9. Check the Situations with Your Host
Sometimes, a script, a query, or a request will take too long so that it will be canceled or killed by the server. In fact, all of these processes will terminate after a certain period of time. Therefore, the error 502 bad gateway fix process can be done via contacting your WordPress hosting provider.
One problem connected to your host is that the platform runs in a non-isolated container. It means that the software that runs each site is a shared one and is not completely private. This greatly increased the chance of seeing 502 bad gateway errors.
Another reason for seeing HTTP status code 502 is because of the fact that the server is not reachable. It means that there is no connectivity or the server is down. So, you’d better contact your host by calling them or sending a ticket. You can also run a ping test to see if messages are reaching your IP or not.
Also Read: How to Fix 504 Gateway timeout Error in WordPress?
10. Check Your Plugins and Themes
A lot of times misused plugins or themes may cause an error. Sometimes, scripts and queries will be canceled because of bad code in WordPress themes or plugins. We have also seen a lot of misconfigured caching plugins that generate a 502 error.
In these cases, the first action can be deactivating them. Then, start to activate them one by one to fix 502 bad gateway errors in WordPress. Always, make sure to update your website plugins to the latest version, and check to ensure you are running a supported version of PHP.
11. Temporarily Disable CDN or Firewall (Faulty Firewall Configurations)
Sometimes, the real cause of 502 error code is related to your website’s firewall or Content Delivery Networks (CDNs). The simplest way, in this case, is to temporarily disable the CDNs if you are using a CDN third-party. You may also be using some plugins for CDNs, so to fix 502 bad gateway error in WordPress, simply deactivate your related plugins.
This error can also happen with providers providing DDoS (Distributed-Denial-of-Attacks) protection, or fully proxy services like Cloudflare that have extra firewalls. This sometimes will happen in Cloudflare’s free plan. Unfortunately, there is no quick solution in this case, since Cloudflare is a fully proxy service. In fact, you’d better know that there are two different 502 bad gateway error variations with Cloudflare as seen below:
- When the problem is connected to your host.
- When the problem is a problem on Cloudflare’s end.
Sometimes, a full firewall configuration will cause the 502 bad gateway error. In this process, a request from a content delivery network will deem as an attack on your server so that the server will reject it. As a result, a 502 bad gateway error occur. To fix the error in this situation, check your firewall configuration to fix the problem.
12. Check Logs
The error log will often help you to fix 502 bad gateway errors in WordPress. Some hosting providers provide you with logs so you can easily see the errors in the log viewer, and quickly fix the issue. This method will help you especially when a plugin is caused the error 502 in WordPress. If your hosting provider doesn’t have a logging tool, you can easily add the following code to your wp-config.php file.
define ("WP_DEBUG', true); define ("WP_DEBUG_LOG', true); define ("WP_DEBUG_DISPLAY', false);
You can also check log files in Apache and NGINX, which commonly are located in the following path:
- Apache: /var/log/apache2/error.log
- NGINX: /var/log/nginx/error.log
13. DNS Issue
When your WordPress site has just migrated to a new host, the DNS issue may cause a 502 error. In this situation, you’d better wait for things to fully propagate from the old host to the new one. This completely depends upon the TTL value of your DNS records. You can also try flush DNS. Flushing your local DNS cache is something like clearing your browser cache.
For the Windows platform, open up a command prompt and type the following:
Ipconfig / flushdns
If it worked, you can see a “Successfully flushed the DNS resolver Cache” message. For macOS users, enter the following in a terminal:
dscacheutil –flushcache
Remember that macOS has no success message for this terminal. You can temporarily change your DNS server. For example, you can change it to a public DNS server such as Google. In some cases, it really works.
14. Restart PHP
Another solution to fix 502 bad gateway error in WordPress is restarting PHP. Some hosting providers provide a tool to make this process easy. But if your host doesn’t provide any tool, you can always ask your hosting support team to restart PHP.
15. PHP Timeout Issue
If you are doing big WordPress imports, PHP Timeout will occur. When this error happens a 502 error will display. In this situation, a single PHP process runs for longer than the max_execution_time or max_input_time. By changing these values, you can fix 502 bad gateway error in WordPress.
Start Blogging
Self-host your WordPress on top-tier hardware, featuring NVMe storage and minimal latency around the world — choose your favorite distro.
Get WordPress VPS
Conclusion
When your WordPress hosting gets an invalid response for the requested page, a 502 error will occur. In this article, we’d discussed 502 bad gateway error in WordPress as well as three main issues that cause this kind of HTTP Status Codes. This error is quite annoying because it can be created with a lot of different things.
Therefore, the process of troubleshooting and finding the real cause takes some time. But, with the suggested solutions we’ve discussed, you can save your time and fix the 502 bad gateway error in WordPress sites.
FAQ
What Does Error 502 Mean?
The HTTP Error 502 means a server error and indicates that the server is acting as a proxy or a gateway. The troubleshooting of this error is a bit annoying because the various things can cause it.
How Do I Fix Error 502?
To fix the error 502 bad gateway, you can try the following solutions:
- Refresh the page
- Restart your computer and networking equipment
- Start a new browser session or load the site with a different browser
- Clear the cache and cookies
- Contact your Internet Hosting Provider
- Disable your firewall
- Check your WordPress plugins and themes.
Is 502 Bad Gateway Error Bad?
Every error can be annoying and makes your users have an awful experience. Since this error is a general indicator that tells you there is something wrong with your site, it can be bad. Therefore, you can try to fix it as soon as possible.
Does 502 Bad Gateway Mean “I am Blocked”?
502 Bad Gateway error doesn’t really mean a block. This error indicates that the edge server was not able to get a valid response from an upstream server. Therefore, this error has happened.
What Causes Bad Gateway?
It may happen by network errors such as DNS issues, ISP-related issues, routing problems, or the problems related to the server software timeouts, or even can be created by slow queries.
If you’re a site owner, few things make your stomach drop like trying to load your website only to receive a cryptic error message. You’re probably familiar with the 404 Page Not Found error, but what about the 502 Bad Gateway issue?
Fortunately, the 502 error is usually easy to fix. Once you’ve found the source of the problem, resolving it is something most WordPress users can do on their own, without advanced technical knowledge.
In this article, we’ll cover the different causes of a 502 error. Then, we’ll show you how to isolate and resolve the issue.
What causes the “502 Bad Gateway” error in WordPress?
The 500 series error codes, also known as HTTP status codes, are used to diagnose communication errors between a web browser and website server. Essentially, when a browser tries to connect to a website, it contacts the website’s server to request access. If this request cannot be fulfilled, then a 500 series error is usually returned, explaining what went wrong.
Error 502 indicates a bad gateway. This is when a server attempts to access another server but is unable to complete the request.
Usually the error is not with the website itself, but the server being accessed. The website is simply behaving as a middleman, or “gateway,” but is unable to deliver the requested data.
If your WordPress site is being affected by a persistent 502 error, it may be a server error outside of your immediate control. This error can make your site inaccessible to visitors. It can also negatively impact your search rankings, as search engines may be unable to access your site.
While this is normally an issue with your host’s servers rather than your website, there are still some things you can do to fix the problem. In this next section, we’ll cover some possible solutions.
How to fix the “502 Bad Gateway” issue in WordPress
Before reaching out to your host to see if they can resolve the 502 Bad Gateway error, there are some troubleshooting steps you can take to rule out an issue on your end. If these actions help you fix the error, you might want to keep an eye out for repeat issues. If your site is frequently plagued by the 502 Bad Gateway error, you may want to consider upgrading your hosting services.
1. Refresh the page
As with most server issues, simply refreshing the page is always worth a try. If the error was very temporary or just a fluke, it might go away with a refresh.
A temporary blip or loss of service from an upstream server might resolve itself, allowing for the connection to complete on the next attempt. Sometimes a spike in traffic or loss of connection at the target server can also cause issues. As you’re troubleshooting, you may want to refresh every so often to see if the error persists.
If refreshing the page solves the problem, it’s safe to assume that the source of the cause was your host. These issues usually resolve themselves quickly.
2. Clear your cache and DNS
On rare occasions, a full cache on the client’s end can simulate server errors, as it’s unable to receive new data as requested. While this is unlikely to return a 502 Bad Gateway error, clearing the cache is a quick and easy fix that can help you rule out the issue.
Let’s look at how to clear the cache in Google Chrome. Most other browsers will follow a similar process.
First, click on the three-dot icon in the top right corner of the browser window and select Settings. Then, navigate to Security and Privacy on the left.
Here, select Clear browsing data. A popup window will appear. You’ll want to select All time as the time range, and check the box for Cached images and files.
Then, just click on the Clear data button and your cache will be emptied. This will free up space for new data.
You may also want to check your Domain Name System (DNS). Like your browser cache, clearing your DNS could be a quick fix if there’s an issue with an IP address.
To clear your DNS, simply open the command prompt and type in the following command:
C:/Users/example>
C:/Users/example>ipconfig /flushdns
After clearing your cache and DNS, try refreshing the page to see if the problem has been resolved. If it’s still there, you can move on to the next method.
3. Deactivate your plugins and theme
If the 502 Bad Gateway error cropped up after installing a new theme or plugin, it’s possible that one of these programs could be the culprit. A poorly coded or incompatible plugin could cause a conflict that results in a server being slow or unable to communicate.
To find out if this is the case, you’ll need to deactivate your plugins. If you still have access to your site, go to your WordPress admin area and navigate to Plugins. Then, select and deactivate any new plugins you’ve installed:
Alternatively, you can deactivate all of your plugins at once to see if the issue resolves itself. If it does, you’ll have to reactivate your plugins one at a time in order to see which one is acting up.
If you’re unable to access your WordPress admin dashboard, you’ll need to go through a backdoor to manually deactivate your plugins. You have two options: connect to your website via the File Manager in your hosting account, or use a File Transfer Protocol (FTP) client like FileZilla.
We’ll be using FileZilla to show you how to connect to your site’s back end and deactivate your plugins. You’ll need to enter your credentials, including username and server address. You can obtain this information from your hosting account.
Once you’ve connected to your site, you’ll need to navigate to the root folder. This contains all of your site’s files, and is normally called www, public, or public_html.
Then, open your wp-content folder and locate the plugins folder.
Next, rename the folder from plugins to something else, like plugins_old. This will break the pathway and all plugins on your site will be deactivated.
Now, try to refresh your page. If the issue hasn’t been resolved, then your plugins are not the culprit and you can rename the folder back to plugins to reestablish the pathway.
If deactivating the plugins resolves the issue, you’ll need to find out which one is at fault. To do this, rename the plugins folder back to its original name. Then, rename the folders for the individual plugins and keep refreshing the page until you find which one is causing the error.
Renaming each individual folder will break the pathway to just one plugin, rather than all of the plugins at once. Once you have identified the faulty plugin, you can access your WordPress admin dashboard to address it accordingly. For instance, you might decide to delete the plugin and install an alternative.
You can follow a similar procedure to check your themes. These are located in the themes folder within wp-content.
If the problem persists after deactivating your plugins and theme, you can rule out bad code as the cause. Let’s look at a few other possible solutions.
4. Check your updates
WordPress developers are constantly updating plugins and themes to fix bugs, improve features, and solve security issues. It’s crucial to keep your site updated not only for security, but also to avoid compatibility issues.
Some themes and plugins are only designed to be compatible with certain versions of WordPress. When installing a new tool, you’ll want to check the required WordPress version.
In the example below, you can see that a WordPress version older than 5.0 or newer than 5.9.1 may not be compatible with the plugin.
This could lead to unexpected behavior from the plugin. Incompatibility issues can cause crashes, long loading times, and time outs that could result in the 502 error.
You can check your current version of WordPress by navigating to Home → Updates in your dashboard.
While you’re here, you can run any necessary updates. You might also want to go to your Plugins page to make sure that all of your software is up to date.
5. Disable the CDN or firewall
If you’re using a content delivery network (CDN) for WordPress, this may increase the chance of a 502 Bad Gateway error as data is being transmitted from and through multiple servers. If there’s a problem with any of these gateways, it could result in an error.
To rule this out, you can disable your CDN to see if there are any changes. If you’re using a plugin to integrate a CDN, simply deactivate that plugin as shown above. If your CDN comes with its own page on your dashboard, there’s likely a setting that allows you to disable it directly.
Security services like firewalls can also cause the 502 Bad Gateway error. These extra layers of security often rely on additional gateways which can fail or delay the request long enough to time out and cause an error. Turning off your firewall temporarily can help you rule out this as a cause.
6. Contact your hosting provider
If none of the above solutions seem to solve the problem, it’s likely that the cause is coming from a hosting server. Try contacting your hosting provider to see if they’re aware of any issues or outages that could be affecting your site. It may be as simple as a server overload or scheduled maintenance. Additionally, a power outage may temporarily affect the service.
Remember that the 502 Bad Gateway error can shut down traffic and negatively impact your site’s search engine rankings. If the source of the problem is your host, and the issue occurs often or for extended periods of time, you may want to consider more reliable hosting options to avoid future problems.
7. Restore a backup
In the event that you can’t find a solution or your host is unable to identify any issues on their end, you can try restoring a backup of your website. If the backup does solve the problem, you’ll need to do some detective work to find out what’s causing the error. This means you’ll need to track any changes you’ve made since the last backup.
As you can imagine, this may be a little time-consuming. Fortunately, you can use a powerful tool like Jetpack Backup to streamline the process. This user-friendly plugin automatically creates backups that you can revert to for any reason.
Moreover, Jetpack comes with an activity log that tracks every change you make to your site. This way, you can easily identify any recent changes that may have caused the 502 Bad Gateway error.
How to avoid the 502 status error in the future
As we have seen, the 502 status error can make your site inaccessible, which can harm your search rankings and conversions. Fortunately, there are steps you can take to prevent bad gateway errors in the future. Let’s look at some effective precautions.
1. Vet new plugins and themes
Whenever you add a new plugin or theme to your site, you’ll want to vet it for quality and compatibility. It’s important to make sure that any code you’re adding to your site is coming from a reputable source. You may also want to check the reviews for any known issues.
Some themes and plugins are only compatible with certain versions of WordPress. Ideally, you’ll only install plugins that are regularly updated.
Keeping your WordPress core, plugins, and themes up to date is also important. Updates usually fix bugs and gaps in security that can cause a number of issues.
Outdated plugins may lose compatibility with newer versions of WordPress, which can lead to errors on your site. Therefore, you may want to enable auto-updates on your site to avoid issues in the future.
2. Upgrade to a more powerful hosting solution
One of the most important things you can do to prevent the 502 Bad Gateway error is to ensure that you have adequate resources for your site.
If your growing website is receiving more and more traffic every day, you may need to upgrade your tier of service to meet these demands. If your hosting server or allocation on that server is overloaded, requests are much more likely to time out and cause the 502 Bad Gateway error.
Therefore, you might want to upgrade to a more advanced tier. Alternatively, you might consider switching to a different hosting plan, like dedicated or Virtual Private Server (VPS) hosting.
3. Check your WordPress error logs
If you encounter the 502 Bad Gateway error intermittently and have not been able to nail down the cause of the problem, checking your error logs may help give you some clues. For example, if the error occurs at your highest traffic times, it’s likely that these spikes are overloading the server.
You can find your error logs in the same directory as your themes and plugins. Connect to your site via FTP or the File Manager in your hosting account, and open the wp-content folder. Here, you’ll see a file called debug.log.
If you can’t find this file, you may need to activate your log errors. You can then open the file to find and fix the error.
By practicing safe habits and being aware of changes to your site, you can prevent many connection errors. As always, regular backups offer peace of mind and enable you to rule out errors on your end. Having a suitable host is also important for handling all of your traffic and maintaining quick load times.
There’s no such thing as being too prepared
As we’ve seen, the 502 Bad Gateway error can have a negative impact on your site’s SEO and availability. Therefore, it’s important that you know how to diagnose it and prevent future issues.
Whenever you encounter this error, you may want to try refreshing the page and clearing your browser cache. If that doesn’t resolve the issue, you might need to deactivate your plugins, disable your CDN, or contact your host for assistance.
Alternatively, you could restore a backup of your site. By using a service like Jetpack Backup, you can easily restore previous versions of your content. If the error goes away, then the cause was likely a change made since the time of that backup. You can then use Jetpack’s activity log to track these changes and resolve the issue.
This entry was posted in Learn. Bookmark the permalink.
Simon Keating
Simon has worked in marketing and product development for over 10 years, previously at HubSpot, Workday, and now Automattic (Jetpack). He has a varied education, with a degree in chemical engineering and a masters in computer science to his name. His passion is helping people and their businesses grow.
Explore the benefits of Jetpack
Learn how Jetpack can help you protect, speed up, and grow your WordPress site.
Get up to 51% off your first year.
Compare plans