Nginx upstream 长连接没生效,TIME_WAIT 猛涨

只写 upstream 里的 server 是不够的,默认对后端走短连接,请求一多后端侧 TIME_WAIT 就猛涨。要显式做三件事:upstream 块里加 keepalive 参数(按后端实例规模配)、proxy_http_version 设为 1.1、proxy_set_header Connection 置为空串。最后这条最容易漏,不置空会把长连接又关回去。改完在后端用 ss 看连接数是否稳定即可验证。

upstream backend {
    server 127.0.0.1:8080;
    keepalive 32;
}

location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_pass http://backend;
}
THE END
喜欢就支持一下吧
点赞12 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容