nginx protocol_error ai_generated partial

上游在读取响应头时发送了HTTP/1.0响应

upstream sent HTTP/1.0 response while reading response header from upstream

ID: nginx/upstream-sent-http-1-0-response-while-reading-response-header-from-upstream

其他格式: JSON · Markdown 中文 · English
80%修复率
85%置信度
1证据数
2023-05-20首次发现

版本兼容性

版本状态引入弃用备注
nginx 1.18.0 active
nginx 1.20.0 active
nginx 1.22.0 active
nginx 1.24.0 active

根因分析

上游服务器以HTTP/1.0而非HTTP/1.1响应,导致nginx拒绝或以不同方式处理头部。

English

Upstream server responded with HTTP/1.0 instead of HTTP/1.1, causing nginx to reject or handle headers differently.

generic

官方文档

https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version

解决方案

  1. Configure the upstream server to use HTTP/1.1. For example, in Apache HTTPD as upstream, set:
    
    <IfModule mod_remoteip.c>
        RemoteIPHeader X-Forwarded-For
        RemoteIPInternalProxy 10.0.0.0/8
    </IfModule>
    
    And ensure mod_proxy_http uses HTTP/1.1 by default.
  2. Add proxy_http_version 1.1; and proxy_set_header Connection ""; to nginx location block:
    
    location / {
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_pass http://upstream;
    }
  3. If upstream cannot be changed, use nginx as a reverse proxy with proxy_pass http://upstream; and set proxy_http_version 1.0; to match upstream behavior:
    
    location / {
        proxy_http_version 1.0;
        proxy_set_header Connection close;
        proxy_pass http://upstream;
    }

无效尝试

常见但无效的做法:

  1. 70% 失败

    This forces nginx to use HTTP/1.0 to upstream, but the upstream might still send HTTP/1.0 responses, and nginx may still reject them if it expects HTTP/1.1.

  2. 90% 失败

    The issue is not buffer size but protocol version mismatch; buffer size does not change the response version.

  3. 80% 失败

    Keepalive settings affect connection reuse, not the HTTP version of responses.