nginx protocol_error ai_generated true

upstream sent invalid HTTP version while reading response header from upstream

ID: nginx/upstream-sent-invalid-http-version

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
1Evidence
2024-03-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx-1.24.0 active
nginx-1.25.3 active
nginx-1.26.0 active

Root Cause

The upstream server returns a response with an unrecognized or malformed HTTP version string (e.g., HTTP/1.0, HTTP/2.0, or HTTP/3).

generic

中文

上游服务器返回的响应中包含无法识别或格式错误的 HTTP 版本字符串(例如 HTTP/1.0、HTTP/2.0 或 HTTP/3)。

Official Documentation

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

Workarounds

  1. 90% success Set proxy_http_version to 1.1 or 2.0 in the location block to match the upstream server's expected protocol. Example: location /api/ { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Connection ""; }
    Set proxy_http_version to 1.1 or 2.0 in the location block to match the upstream server's expected protocol. Example:
    location /api/ {
        proxy_pass http://backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
  2. 85% success If the upstream is a custom or legacy server, ensure it returns a valid HTTP version string (e.g., 'HTTP/1.1 200 OK'). Check the upstream application logs for version misconfiguration.
    If the upstream is a custom or legacy server, ensure it returns a valid HTTP version string (e.g., 'HTTP/1.1 200 OK'). Check the upstream application logs for version misconfiguration.

中文步骤

  1. Set proxy_http_version to 1.1 or 2.0 in the location block to match the upstream server's expected protocol. Example:
    location /api/ {
        proxy_pass http://backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
  2. If the upstream is a custom or legacy server, ensure it returns a valid HTTP version string (e.g., 'HTTP/1.1 200 OK'). Check the upstream application logs for version misconfiguration.

Dead Ends

Common approaches that don't work:

  1. 60% fail

    Forcing HTTP/1.0 on a modern upstream that uses chunked encoding or keepalive will cause protocol mismatch.

  2. 90% fail

    The error is about the response version, not the request path.

  3. 95% fail

    This error is a protocol-level error, not a buffer size issue.