首页/系统/Linux 运维命令速查/场景:HTTP 接口超时/502 排查
本包目录(613 条)
文件与目录76 条文本处理77 条
网络命令82 条
进程与作业69 条磁盘与文件系统51 条用户与权限44 条日志与排查40 条systemd 与服务42 条包管理34 条性能与监控48 条定时任务与计划50 条

场景:HTTP 接口超时/502 排查

先用 curl 分清「连不上、慢、还是返回错」:状态码 + 耗时分解 + 绕过 DNS/网关直连后端,再决定查 Nginx、后端还是网络。

Linux 运维命令速查系统更新于 2026-10-12
场景接口 502/504/超时
组合curl -w 耗时 + --resolve 直连 + tcpdump

耗时分解

耗时分解
curl -sS -o /dev/null -w 'dns=%{time_namelookup} conn=%{time_connect} tls=%{time_appconnect} ttfb=%{time_starttransfer} total=%{time_total} code=%{http_code}\n' --max-time 15 https://api.example.com/health

直连后端对比

直连后端对比
curl -sS --resolve api.example.com:443:10.0.0.9 -o /dev/null -w 'code=%{http_code} total=%{time_total}\n' https://api.example.com/health
curl -sS -o /dev/null -w 'code=%{http_code} total=%{time_total}\n' http://10.0.0.9:8080/health     # 后端本机直测

旁证

旁证
ss -tn state established '( dport = :8080 )' | wc -l   # 后端连接数(后端机上)
tail -n 50 /var/log/nginx/error.log
ttfb 高 + 后端直测也慢 → 应用问题;前端慢后端快 → 网关/网络问题;cert 报错先跑 openssl s_client。

易错点

  • -w 里的 time_starttransfer(TTFB)本身包含 TLS 时间:要算纯服务端处理时间用 ttfb 减 tls
  • 关注 DNS 时间是否异常(time_namelookup 大):解析慢是很多「接口慢」的隐藏原因

数据来源与参考

  • curl 官方文档(curl.se/docs/manpage.html)

相关工具

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