错误日志与配置
错误日志与配置
tail -100 /var/log/nginx/error.log | grep -E 'upstream timed out|connect\(\) failed|upstream prematurely closed'
# 配置示例(nginx.conf / conf.d):
# proxy_connect_timeout 3s;
# proxy_send_timeout 30s;
# proxy_read_timeout 30s;
# proxy_next_upstream error timeout http_502 http_504;状态与含义
| 状态码 / 日志 | 含义与方向 |
|---|---|
| 502 Bad Gateway | 连不上上游 / 上游提前关闭连接 |
| 504 Gateway Timeout | 读上游响应超时(后端处理太久) |
| connection refused | 上游端口没监听(服务挂了或重启中) |
| upstream prematurely closed | 上游中途关闭连接(崩溃/被杀) |
| 499(客户端关闭) | 客户端等不及先断开,常因后端太慢 |
调整 proxy_read_timeout 之前,先拿 $upstream_response_time 看后端真实耗时:如果后端稳定在 40s,把超时从 30s 提到 60s 只是让慢请求变『慢成功』。