没有人喜欢错误代码!对于大多数用户来说,看到错误编号根本没有帮助,因为除非您记住了相关的密码本,否则该数字没有任何意义。
如果您遇到“502 Bad Gateway Error”,那么问题几乎可以肯定是内部服务器错误。了解问题至关重要,在某些情况下,您可以采取一些措施来解决问题。我们将解释这个错误的含义,并探索让事情重新启动和运行的方法。
HTTP 状态码
502 错误代码是HTTP错误响应代码集的一部分。HTTP或超文本传输协议(Hypertext Transfer Protocol )是使 Web 工作的核心协议。它是更大的互联网协议套件的一部分,描述了服务器和客户端在请求或发送 Web 内容时如何相互通信。
当您的 Web 浏览器(客户端)使用HTTP(HTTP)从服务器请求数据时,出现问题时,Web 服务器会给出无效响应,从而导致错误代码。其中最著名的可能是Error 404,这意味着服务器无法在您指定的地址找到页面。
5xx 错误代码系列
有五组编号的错误响应代码:1xx、2xx、3xx、4xx 和 5xx。
5xx 代码组是所有服务器错误代码。这意味着当您看到以数字 5 开头的代码时,几乎可以肯定问题出在服务器上。大多数情况下,如果服务器出现问题,您所能做的就是等待并稍后重试。一般来说,这些都是暂时的错误。如果您尝试访问Amazon或Google之类的主要服务,除非出现重大中断,否则这些错误几乎可以立即解决。
什么是“网关”?
错误 502 是“错误网关”错误。网关设备是计算机网络上的一个节点,它充当网络中更上游的其他 Web 资源的网关。
您的互联网路由器或调制解调器是网关(gateway)设备。您的ISP用来将其用户连接到 Internet 的主要干线的大型路由器也是如此。如果您想了解更多关于这一切如何组合在一起的信息,请阅读谁拥有互联网?网络架构解释(Who Owns the Internet? Web Architecture Explained)。
“坏(Bad)网关”仅意味着网关设备无法从网络中的上游服务器检索您请求的数据。网关不好,不好 !(Bad)
HTTP 502 错误的常见原因
502 错误的发生可能有多种原因,但大多数是服务器端问题。到目前为止,源服务器过载是最常见的原因。源服务器(origin server)是包含网站并侦听用户请求以提供该内容的计算机。
服务器过载
可能有太多人同时向服务器发出请求,因此它无法满足超出其能力的任何请求。您甚至可能会看到“502 服务暂时过载”错误,而不是“网关错误”。
DDoS 攻击
有时在DDoS(分布式拒绝(Denial)服务(Service))攻击期间服务器会故意超载,但结果是相似的。如果服务器耗时过长,则会算作服务器超时,并且您会收到错误代码。DDoS攻击不像过去那样普遍,这要归功于CloudFlare等服务,它充当服务器和大量请求之间的缓冲区。因此,您遇到的任何过载很可能是合法的高使用率。
服务器配置错误
服务器的防火墙(firewall)或网络设置可能配置错误或错误地将您的 IP 地址识别为应被阻止的地址。如果您使用的是动态 IP 地址(大多数人都这样做),那么您可能已经分配了一个有问题的用户以前使用过的地址。
互联网非常复杂,在您的设备和您尝试访问的服务器之间有数十个甚至数百个网络设备设备。他们中的一些人可能遇到了麻烦。
越野车服务器
最后,服务器实际上可能只是停机或存在软件错误,使其无法满足请求。请记住(Remember),服务器只是一台计算机,可能有人或某事把它搞砸了。所以在有人调试软件之前,问题会一直存在。您会在网络上找到数百篇文章,详细介绍如何解决Apache 网络服务器软件的问题、堵住(Apache webserver software)PHP 代码(PHP code)中的漏洞,或解决他们的WordPress 站点(WordPress sites)的配置问题。
现在您已经对问题有了一个很好的基本了解,我们将看看您在解决问题时可以尝试的一些事情。
刷新页面
如果您遇到 502 错误,您应该做的第一件事是刷新网页。大多数此类错误的发生要么是因为某处存在临时网络问题,要么是因为服务器超载。您也可以选择等到高峰时间结束(基于服务器位置的时区)再重试。在 99% 的 502 错误案例中,稍后再试就是答案,但在您等待时,您还可以做一些其他的事情。
检查网站(Site)是否对所有人都已关闭(Down)
虽然 502 错误表明服务器端的连接存在问题,但确保您不是唯一遇到问题的人永远不会受到伤害。您可以使用IsItDownRightNow 之类的网站吗?(IsItDownRightNow?)或Down Detector以确认您不是唯一一个查看错误代码而不是Facebook 上(Facebook)您妈妈的狗的最新照片的人。
其中一些网站可以向您显示重要的详细信息,例如网站出现故障的频率、是否只是在某些地区出现故障以及其他用户目前是否在抱怨特定问题。
重置您的路由器
有时,坏网关就是您家中的网关。您的路由器和其他任何计算机一样都是一台计算机,这意味着它可能会挂起、崩溃或出现错误。与您的其他计算机一样,简单的重新启动通常可以解决这些问题。
假设您发现您必须经常重置您的路由器(reset your router)才能让您的互联网连接再次正常工作。在这种情况下,您可能需要执行固件更新或考虑购买容量更大的新路由器以同时处理大量设备。
清除浏览器缓存和 Cookie
[9 清除.jpg]( [9 Clear.jpg])
您的浏览器会缓存您经常访问的网站以及您最近访问的网站。通过维护缓存,您可以获得更快的站点响应时间,并且您将使用更少的带宽来启动,因为您不会在每次刷新或重新访问页面时下载页面的常见元素。
不幸的是,Web 浏览器缓存可能会出错并妨碍正确加载页面。因此,您可能需要清除浏览器的缓存。不用担心丢失您的历史记录、密码和其他重要信息。所有清除缓存可能会降低站点访问速度,直到可以建立新的缓存。如果您想知道如何清除 Web 浏览器的缓存,请查看我们的终极教程:如何清除任何 Web 浏览器的缓存(How To Clear The Cache Of Any Web Browser)
Cookie 是您的浏览器在本地保存的另一种类型的数据,可能会干扰网站加载。一般来说(Generally),cookies 有利于网站体验。它们让网站“记住”有关您的信息,这样您就不必每次都登录或在连接中断时丢失购物车中的内容。
除了可能会扰乱网站的工作之外,跟踪 cookie(tracking cookies)也可能是一个隐私问题,但无论哪种方式,我们的教程如何清除任何 Web 浏览器的历史记录(How to Clear Any Web Browser’s History)也向您展示了如何清除 cookie。请务必仅清除 cookie 而不是您的实际浏览历史记录!
更新您的浏览器
如果只是为了确保您安装了最新的安全补丁,您应该始终让您的网络浏览器保持最新状态。如果您有待处理的更新,请先完成它们,然后再访问向您发送错误的网站。可能只是您的浏览器需要最新的网络标准才能与最新的网站技术交流。
确保您的操作系统也是最新的不会有什么坏处,因为可能存在与您的计算机或设备的网络驱动程序或网络堆栈相关的问题。
尝试不同的浏览器
并非每个浏览器都是平等的。如果您使用的是嵌入式网络浏览器或其他一些鲜为人知的浏览器,它可能不支持给定网站的所有功能或要求。
也可能只是您使用的浏览器出现问题。消除浏览器作为问题根源的最快方法是使用不同的浏览器。有很多可供选择,包括Microsoft Edge、Safari(Mac或 iOS)、Mozilla Firefox和Google Chrome,仅举几例。
停用插件和扩展
启动浏览器或(暂时)禁用所有插件和扩展以消除它们作为问题的根源可能是值得的。仅当使用没有这些扩展的其他浏览器不会在同一 Internet 连接上显示问题时才执行此操作。
尝试不同的 Internet 连接
如果您尝试访问的服务器正常,但通往该服务器的路由上的网关设备是问题的根源,您可能希望通过使用不同的 Internet 连接来强制使用不同的路由。
例如,如果您的家庭宽带连接出现错误,请尝试使用移动数据连接从智能手机访问该站点。除非两个连接都来自同一个ISP,否则这应该绕过任何ISP特定的问题。
检查您的代理服务器
如果您使用的是代理服务器,则问题中的错误网关实际上可能是该代理服务器本身。许多工作场所的计算机通过公司代理服务器运行,并且并非总是可以通过设计绕过这些。毕竟,该公司使用代理服务器来监控您在互联网上的行为并控制其信息安全。
假设(Suppose)您无法绕过代理服务器(proxy server)配置中的代理服务器连接。在这种情况下,您唯一的选择是通过询问 IT 部门来检查代理服务器是否正常工作。如果您使用的是私有代理服务,请将其关闭以检查是否是导致问题的原因。如果您正在运行自己的家庭代理服务器,请重新启动它并检查它是否仍然配置正确。
试试 VPN
虽然我们喜欢提及“网络服务器”,但事实上大多数网络内容都托管在多个服务器上。内容交付网络(Delivery Networks)( CDN(CDNs) ) 将 Web 内容的副本保存在遍布全球的多台服务器上。因此,当您请求访问该站点时,内容由离您最近的CDN节点提供服务,提供最佳速度和响应时间。使用本地带宽也比通过国际干线发送数据更便宜,因此公司更喜欢使用CDN(CDNs)。
问题是,如果您的本地CDN节点过载或出现问题,您可能会收到 502 错误。理论上,您应该被路由到下一个工作服务器节点。但以防万一,您可以尝试使用VPN(虚拟专用网络(Private Network))从您所在国家/地区的其他国家或地区访问该网站。这可能会绕过本地服务器问题。
刷新(Flush)您的DNS 缓存(DNS Cache)或更改您的 DNS 服务器(Change Your DNS Servers)
DNS(域名系统(Domain Name System))服务器就像互联网的电话簿。当您在地址栏中键入https://www.online-tech-tips.com(我们的姊妹站点)之类的地址时,DNS服务器会将其转换为物理服务器的正确 IP 地址,该地址将向您发送您的信息要求。
给定的DNS服务器可能在文件中具有错误的 IP 地址(它可能已更改),或者它引用您的服务器可能是该站点的多个服务器之一,并且该服务器有问题。您的本地DNS缓存也可能已损坏或过期。
您应该首先尝试清除 DNS 缓存(clear your DNS cache),然后重试。如果这不起作用,您可以更改 DNS 服务器(change your DNS servers)以查看是否解决了问题。
位于 8.8.8.8 和 8.8.4.4 的Google公共 DNS服务器是世界上最快、最可靠的(Public DNS)DNS服务器之一。
改用缓存页面
如果您需要的只是网站上的静态信息,那么您可能根本不需要服务器启动并运行。谷歌(Google)和其他搜索引擎不断地索引网络并制作网页的缓存副本。还有一些网站,例如Internet Wayback Machine,它会同时归档新旧网页,以便您可以查看它们在不同时间点拥有的信息。
使用Google(Google)很容易查看页面的缓存版本,只需查找结果标题右侧的三个点(three dots to the right of the result header)并选择它。
从弹出的菜单中,选择cached。
然后,您会在顶部看到带有此消息的页面。
联系站点管理员
当遇到 502 Bad Gateway错误时,我们可以提供的最后一条建议是与网站管理员联系。如果问题似乎出在您的ISP上,您可以联系他们的客户支持并询问他们是否知道访问该特定站点的任何问题。
许多ISP(ISPs)在其主页或用户帐户仪表板上都有“已知问题”部分,因此请务必检查这些部分。最后,如果本文中的任何内容都没有帮助,那么它实际上是你无法控制的,你所能做的就是等待。那么为什么不查看我们的有趣的东西部分来了解一些打发时间的好方法呢?
What Is a 502 Bad Gateway Error (And How to Fix It)
No one likеs an error code! For most users seeing an error number isn’t helpful at all because the number doesn’t mean anything unless you’ve memorized the relevant codebook.
If you run into a “502 Bad Gateway Error”, the problem is almost certainly an internal server error. It’s essential to understand the problem and, in some cases, there are a few measures you can take to resolve the issue. We’ll explain what this error means and explore ways to get things up and running again.
HTTP Status Codes
The 502 error code is part of the HTTP error response code set. HTTP or Hypertext Transfer Protocol is the core protocol that makes the web work. It’s part of the larger internet suite of protocols and describes how servers and clients talk to each other when requesting or sending web content.
When your web browser (the client) requests data from a server using HTTP, and something goes wrong, the web server gives an invalid response resulting in an error code. The most famous of these is probably Error 404, which simply means the server can’t find a page at the address you’ve specified.
The 5xx Error Code Family
There are five numbered sets of error response codes: 1xx, 2xx, 3xx, 4xx, and 5xx.
The 5xx code group is all server error codes. This means when you see a code starting with the number five, the problem is almost certainly with the server. Most of the time, if something has gone wrong with the server, all you can do is wait and try again later. In general, these are temporary errors. If you’re trying to access a major service from the likes of Amazon or Google, these sorts of errors are almost immediately resolved unless there’s a major outage.
What’s a “Gateway”?
Error 502 Is a “Bad Gateway” Error. A gateway device is a node on a computer network that serves as a gateway to other web resources further upstream in the network.
Your internet router or modem is a gateway device. So are the mega routers that your ISP uses to connect its users to the major trunks of the internet. If you want to know more about how it all fits together, read Who Owns the Internet? Web Architecture Explained.
A “Bad Gateway” then simply means that the gateway device could not retrieve the data you asked for from upstream servers in the network. Bad gateway, bad!
Common Causes of the HTTP 502 Error
The 502 error can happen for various reasons, but most are server-side problems. An overloaded origin server is by far the most common reason. An origin server is a computer that contains the website and listens for requests from users to serve that content.
Server Overload
There may be too many people making requests of the server simultaneously, so it fails to honor any beyond its capacity. You may even see a “502 service temporarily overloaded” error instead of “bad gateway.”
DDoS Attacks
Sometimes servers are overloaded on purpose during a DDoS (Distributed Denial of Service) attack, but the result is similar. If the server takes too long, it will count as a server timeout, and you’ll get an error code. DDoS attacks aren’t as common as they’ve been in the past, thanks to services like CloudFlare, that act as a buffer between a server and a flood of requests. So any overload you encounter is most likely legitimate high usage.
Server Misconfiguration
The server’s firewall or network settings may be misconfigured or erroneously identify your IP address as one that should be blocked. If you’re using a dynamic IP address (as most people do), you may have been assigned an address that a problematic user previously used.
The internet is incredibly complicated, and there are dozens, even hundreds of networking equipment devices between your device and the server you’re trying to access. Some of them might be having trouble.
Buggy Servers
Finally, the server might actually just be down or have software bugs that make it unable to fulfill requests. Remember, a server is just a computer, and someone or something may have messed it up. So until someone debugs the software, the problem will persist. You’ll find hundreds of articles on the web detailing how to fix issues with Apache webserver software, plugging holes in PHP code, or resolving configuration issues with their WordPress sites.
Now that you’ve got a good basic idea of the problem, we’ll look at the handful of things you can try when troubleshooting the issue.
Refresh the Page
If you’re faced with a 502 error, the first thing you should do is to refresh the web page. Most errors like this happen either because there’s a temporary network issue somewhere down the line or because the server is overloaded. You can also choose to wait until peak times are over (based on the time zone of the server location) before trying again. In 99% of 502 error cases, trying again later is the answer, but while you’re waiting, there are some other things you can do.
Check if the Site Is Down for Everyone
While a 502 error suggests that there’s a problem at the server’s end of the connection, it never hurts to make sure that you’re not the only one having issues. You can use websites like IsItDownRightNow? Or Down Detector to confirm that you aren’t the only one looking at an error code instead of the latest pictures of your mom’s dogs on Facebook.
Some of these sites can show you important details such as how often a site goes down, whether it’s just down in certain regions, and whether any other users are complaining about specific problems at the moment.
Reset Your Router
Sometimes the bad gateway is the gateway in your house. Your router is a computer just like any other, which means it can hang, crash, or suffer from bugs. Like your other computers, a simple restart can usually resolve these issues.
Suppose you find that you have to reset your router often to get your internet connection working again. In that case, you may want to perform a firmware update or consider buying a new router with more capacity to handle lots of devices at once.
Clear Browser Cache and Cookies
[9 Clear.jpg]
Your browser keeps a cache of websites you visit often and those you’ve visited most recently. By maintaining a cache, you get faster site response times, and you’ll use less bandwidth to boot since you aren’t downloading common elements of the page every time you refresh or re-visit it.
Unfortunately, web browser caches can go wrong and get in the way of loading a page properly. So you may want to clear your browser’s cache. Don’t worry about losing your history, passwords, and other important information. All clearing the cache will do is perhaps slow down site access for a bit until a new cache can be built up. If you want to know how to clear the cache for your web browser, check out our ultimate tutorial: How To Clear The Cache Of Any Web Browser
Cookies are another type of data that your browser keeps locally that can interfere with website loading. Generally, cookies are good for the website experience. They let a website “remember” information about you so that you don’t have to log in every time or lose the contents of your shopping cart if your connection is interrupted.
Apart from potentially messing up a site’s working, tracking cookies can also be a privacy problem, but either way, our tutorial How to Clear Any Web Browser’s History also shows you how to clear cookies. Just be sure to clear only the cookies and not your actual browsing history!
Update Your Browser
You should always keep your web browser up to date if only to make sure you have the latest security patches installed. If you have pending updates, complete them first before accessing the website that’s sending you an error. It might just be that your browser needs the latest web standards to speak to the latest website technology.
It can’t hurt to make sure your operating system is also up to date since there may be issues related to network drivers or the network stack for your computer or device.
Try a Different Browser
Not every browser is made equal. If you’re using an embedded web browser or some other lesser-known browser, it may not support all the functionality or requirements of a given website.
It could also simply be that something has gone wrong with the browser you’re using. The fastest way to eliminate the browser as the source of the issue is to use a different browser. There are many to choose from, including Microsoft Edge, Safari (Mac or iOS), Mozilla Firefox, and Google Chrome, to name but a few.
Deactivate Plugins and Extensions
It might be worth starting up your browser or (temporarily) disabling all of your plugins and extensions to eliminate them as a source of the problem. Only do this if using a different browser without those extensions doesn’t show the problem on the same internet connection.
Try a Different Internet Connection
If the server you’re trying to reach is fine, but a gateway device on the route to that server is the source of the issue, you may want to force a different route by using a different internet connection.
For example, if your home broadband connection gives you the error, try accessing the site from your smartphone using your mobile data connection. Unless both connections are from the same ISP, this should bypass any ISP-specific issues.
Check Your Proxy Server
If you’re using a proxy server, the bad gateway in question could actually be that proxy server itself. Many workplace computers run through a company proxy server, and it’s not always possible to bypass these by design. After all, the company uses the proxy server to monitor what you do on the internet and control its information security.
Suppose you can’t bypass your proxy server connection in the proxy server config. In that case, your only alternative is to check if the proxy server is working correctly by asking the IT department. If you’re using a private proxy service, turn it off to check if that’s causing the problem. If you’re running your own household proxy server, reboot it and check if it’s still configured correctly.
Try a VPN
While we like to refer to a “web server,” the truth is that most web content is hosted on multiple servers. Content Delivery Networks (CDNs) keep copies of web content on multiple servers spread worldwide. So when you request access to the site, the content is served by the CDN node closest to you, offering the best speeds and response times. It’s also cheaper to use local bandwidth rather than send data over international trunk lines, so companies favor using CDNs.
The thing is, if your local CDN node is overloaded or having issues, you may get a 502 error. In theory, you’re supposed to be routed to the next working server node. But just in case, you can try using a VPN (Virtual Private Network) to access the website from another country or region within your own country. This may bypass the local server issue.
Flush Your DNS Cache or Change Your DNS Servers
DNS (Domain Name System) servers are like the telephone books of the internet. When you type an address like https://www.online-tech-tips.com (our sister site) into your address bar, the DNS server translates that into the correct IP address of the physical server that will send you the information you require.
A given DNS server may have the wrong IP address on file (it may have changed), or the server it’s referring you to might be one of several for the site, and that one is having problems. Your local DNS cache might also be corrupted or out of date.
You should first try to clear your DNS cache and try again. If that doesn’t work, you can change your DNS servers to see if that resolved the issue.
Google’s Public DNS servers found at 8.8.8.8 and 8.8.4.4 are some of the fastest and most reliable DNS servers in the world.
Use a Cached Page Instead
If all you needed from a website was static information, you might not need the server to be up and running at all. Google and other search engines constantly index the web and make cached copies of web pages. There are also websites such as the Internet Wayback Machine, which archives both old and new web pages so you can see the information they had at various points in time.
It’s easy to see the cached version of a page using Google, just look for the three dots to the right of the result header and select it.
From the menu that pops up, choose cached.
Then you’ll see a page with this message at the top.
Contact the Site Administrator
The last piece of advice we can provide when facing a 502 Bad Gateway error is to get in touch with the website administrator. If the problem seems to be with your ISP, you can contact their customer support and ask if they’re aware of any problems with access to that particular site.
Many ISPs have a “known issues” section on their home pages or user account dashboards, so be sure to check these as well. In the end, if nothing in this article helps, it’s quite literally out of your hands, and all you can do is wait. So why not check out our Fun Stuff section for a few excellent ways to pass the time?