Nginx pstream prematurely closed connection while reading response header from upstream

释放双眼,带上耳机,听听看~!
🤖 由 ChatGPT 生成的文章摘要

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

给TA打赏
共{{data.count}}人
人已打赏
NGINX

Nginx宝塔反向代理OpenAI接口

2023-6-1 14:41:14

Kubernetes报错锦集

k8s Ingress 添加支持带有下划线的Header参数

2023-6-7 14:11:35

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索