http 状态码 502 和 504 有什么区别
Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 51 (opens in a new tab)
Author 回答者: sjfkai (opens in a new tab)
-
502 Bad Gateway The server was acting as a gateway or proxy and received an invalid response from the upstream server. 收到了上游响应但无法解析
-
504 Gateway Timeout The server was acting as a gateway or proxy and did not receive a timely response from the upstream server. 上游响应超时
Author 回答者: shfshanyue (opens in a new tab)
这两种异常状态码都与网关 Gateway 有关,首先明确两个概念
- Proxy (Gateway),反向代理层或者网关层。在公司级应用中一般使用 Nginx 扮演这个角色
- Application (upstream serrver),应用层服务,作为 Proxy 层的上游服务。在公司中一般为各种语言编写的服务器应用,如 Go/Java/Python/PHP/Node 等
此时关于 502 与 504 的区别就很显而易见
502 Bad Gateway
。一般表现为你自己写的应用层服务(Java/Go/PHP)挂了,网关层无法接收到响应504 Gateway Timeout
。一般表现为应用层服务 (upstream) 超时,如查库操作耗时十分钟,超过了 Nginx 配置的超时时间