Nginx pstream prematurely closed connection while reading response header from upstream

2023年 6月 9日 35.5k 0

nginx 报错日志如下

2023/06/02 07:10:45 [error] 459#459: *2424 upstream prematurely closed connection while reading response header from upstream, client: 10.10.12.128, server: workflow-xx.com, request: "GET /engine/engine-rest/deployment/61a70c70-ce01-11ed-b184-72d694cd9503/resources/61a70c71-ce01-11ed-b184-72d694cd9503/data HTTP/1.1", upstream: "http://10.10.124.101:8080/engine/engine-rest/deployment/61a70c70-ce01-11ed-b184-72d694cd9503/resources/61a70c71-ce01-11ed-b184-72d694cd9503/data", host: "workflow-xxx.com", referrer: "http://workflow-xxx.com/deploy/detail/61a70c70-ce01-11ed-b184-72d694cd9503"
2023/06/02 07:10:45 [error] 459#459: *2424 upstream prematurely closed connection while reading response header from upstream, client: 10.10.12.128, server: workflow-xxx.com, request: "GET /engine/engine-rest/deployment/61a70c70-ce01-11ed-b184-72d694cd9503/resources/61a70c71-ce01-11ed-b184-72d694cd9503/data HTTP/1.1", upstream: "http://10.10.124.101:8080/engine/engine-rest/deployment/61a70c70-ce01-11ed-b184-72d694cd9503/resources/61a70c71-ce01-11ed-b184-72d694cd9503/data", host: "workflow-xx.com", referrer: "http://workflow-xxx.com/deploy/detail/61a70c70-ce01-11ed-b184-72d694cd9503"
2023/06/02 07:10:45 [error] 459#459: *2424 upstream prematurely closed connection while reading response header from upstream, client: 10.10.12.128, server: workflow-xx.com, request: "GET /engine/engine-rest/deployment/61a70c70-ce01-11ed-b184-72d694cd9503/resources/61a70c71-ce01-11ed-b184-72d694cd9503/data HTTP/1.1", upstream: "http://10.10.124.101:8080/engine/engine-rest/deployment/61a70c70-ce01-11ed-b184-72d694cd9503/resources/61a70c71-ce01-11ed-b184-72d694cd9503/data", host: "workflow-xx.com", referrer: "http://workflow-xx.com/deploy/detail/61a70c70-ce01-11ed-b184-72d694cd9503"

原因:
HTTP协议中对长连接的支持是从1.1版本之后才有的,因此最好通过proxy_http_version指令设置为1.1,而Connection header应该被清理。清理的意思,是清理从client过来的http header,因为即使是client和nginx之间是短连接,nginx和upstream之间也是可以开启长连接的。这种情况下必须清理来自client请求中的Connection header
http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive

upstream http_backend {
    server 127.0.0.1:8080;

    keepalive 16;
}

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

nginx没有打开和后端的长连接,即:没有设置proxy_http_version 1.1;和proxy_set_header Connection "";从而导致后端server每次关闭连接,高并发下就会出现server端出现大量TIME_WAIT
参考文档https://www.cnblogs.com/liufarui/p/11075630.html

相关文章:

  1. [NGINX] – 配置文件优化 – NGINX.CONF
  2. Nginx 反向代理与正向代理
  3. No server certificate verification method has been enabled
  4. Nginx 代理rancher提示500

相关文章

LeaferJS 1.0 重磅发布:强悍的前端 Canvas 渲染引擎
10分钟搞定支持通配符的永久有效免费HTTPS证书
300 多个 Microsoft Excel 快捷方式
一步步配置基于kubeadmin的kubevip高可用
istio全链路传递cookie和header灰度
REST Web 服务版本控制

发布评论