线上nginx的一次“no live upstreams while connecting to upstream ”分析

可能的原因:
后端服务器的 TCP 队列满了,造成 nginx 连接后端时连接被丢弃,队列满可能是后端 PHP 程序处理速度慢,或者正在做压测。

可以观察后端服务器和 nginx 的 TIME_WAIT 状态连接数,以及建立的连接数。

nginx 报错时用 `netstat -s | grep listen` 观察

netstat -n | awk '/^tcp/ {++state[$NF]} END {for(key in state) print key,"	",state[key]}'

upstream http_backend {
    server 127.0.0.1:8080;

    keepalive 256;
}
server {
    ...

    location /http/ {
        proxy_pass http://http_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        ...
    }
}

参考:https://www.nginx.com/blog/tuning-nginx/
https://xiezefan.me/2017/09/27/nginx-502-bug-trace/

https://www.cnblogs.com/dadonggg/p/8778318.html

原文地址:https://www.cnblogs.com/fan-gx/p/13445781.html