测验:502 · 504 与错误日志签名
error.log 出现 connect() failed (111: Connection refused) while connecting to upstream,客户端收到 502。哪项措施最无效?
- 把
proxy_read_timeout提高到 30s - 确认上游进程确实 LISTEN 该端口
- 确认
proxy_pass地址和端口正确 - 检查上游前是否有防火墙或策略
下面两条 504 error.log 有何不同?
① upstream timed out (110: Connection timed out) while connecting to upstream
② upstream timed out (110: Connection timed out) while reading response header from upstream
- ① 是域名解析失败,② 是 TCP 连接失败
- ① 在连接阶段超时,② 在等待响应头阶段超时
- ① 是上游状态码,② 是 nginx 自己生成
- 情况相同,只因 nginx 版本不同
在 /hang/ 块设置 proxy_read_timeout 30s; 后,请求仍在 2 秒时以 504 结束。最可能是什么?
- 没有 reload,配置未生效
- location 内超时被 http 块覆盖
- 上游 2 秒时关闭连接,与读取超时无关
- 连接阶段先触发
proxy_connect_timeout
健康检查一直正常,但只有部分 SSO 用户收到 502,error.log 显示 upstream sent too big header。原因是什么?
- 这些用户被分配到不同上游
- 响应头超过
proxy_buffer_size - 会话 Cookie 到期,上游返回空响应
- 上游线程池饱和,未发完整头
把 proxy_buffer_size 提到 16k 后,nginx 因 "proxy_busy_buffers_size" must be less than the size of all "proxy_buffers" minus one buffer 拒绝启动。该怎么办?
- 把
proxy_busy_buffers_size显式设为 0 - 关闭
proxy_buffering - 同时增大
proxy_buffers - 把
proxy_buffer_size恢复 4k,并让上游缩小头
访问日志为 413 ut=- rt=0.002 us=- "POST /upload HTTP/1.1",应用日志没有该请求。应如何判断?
- 日志采集遗漏,先查管道
- 上游收到了但没记录,查应用配置
ut和us都是横线,说明从未访问上游- 413 是上游返回,应查上游