首页/网络/网络排障速查/反向代理层排查:区分代理慢与后端慢

反向代理层排查:区分代理慢与后端慢

代理夹在客户端与后端之间:先用日志里的 upstream 耗时把责任切开,再往客户端侧或后端侧走,避免在两层之间来回猜。

网络排障速查网络更新于 2026-10-12
场景经 Nginx/SLB 后访问异常或变慢
工具nginx access/error log、curl 对照直连与经代理
关键字段$request_time、$upstream_status、$upstream_response_time

对照与取证

对照与取证
curl -sS -o /dev/null -w 'direct %{http_code} %{time_total}\n' http://127.0.0.1:8080/api/health
curl -sS -o /dev/null -w 'proxy  %{http_code} %{time_total}\n' -H 'Host: api.example.com' http://10.0.0.5/api/health
tail -50 /var/log/nginx/error.log
grep 'upstream' /var/log/nginx/error.log | tail -20
日志里没有 $upstream_response_time 就先补上再复现:有了它,『代理自身慢』与『后端慢』一眼可分。

易错点

  • 只看请求总耗时,不区分代理自身与应用处理时间
  • 经代理测试却不带 Host 头,被当成默认站点,结论无效

数据来源与参考

  • nginx 文档:ngx_http_upstream_module(upstream_response_time)

相关工具

​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌