nginx protocol_error ai_generated true

upstream sent invalid status line while reading response header from upstream, client: 10.0.0.1, server: example.com

ID: nginx/upstream-sent-invalid-status-line-empty

Also available as: JSON · Markdown · 中文
76%Fix Rate
84%Confidence
1Evidence
2023-11-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx 1.18.0 active
nginx 1.20.1 active
nginx 1.22.0 active
nginx 1.24.0 active

Root Cause

Upstream server sends a malformed HTTP status line (e.g., empty or missing HTTP version), causing nginx to fail parsing the response.

generic

中文

上游服务器发送了格式错误的 HTTP 状态行(例如,空行或缺少 HTTP 版本),导致 nginx 无法解析响应。

Official Documentation

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

Workarounds

  1. 85% success Fix the upstream application to return a valid HTTP status line. For example, in a Python WSGI app, ensure the application returns a proper start line: def application(environ, start_response): status = '200 OK' headers = [('Content-Type', 'text/plain')] start_response(status, headers) return [b'Hello World'] Check for missing or empty status strings in custom servers.
    Fix the upstream application to return a valid HTTP status line. For example, in a Python WSGI app, ensure the application returns a proper start line:
    def application(environ, start_response):
        status = '200 OK'
        headers = [('Content-Type', 'text/plain')]
        start_response(status, headers)
        return [b'Hello World']
    Check for missing or empty status strings in custom servers.
  2. 70% success Use nginx's proxy_pass with a rewrite to a different upstream that sanitizes responses, or place a reverse proxy like Varnish in front of the misbehaving upstream to normalize responses.
    Use nginx's proxy_pass with a rewrite to a different upstream that sanitizes responses, or place a reverse proxy like Varnish in front of the misbehaving upstream to normalize responses.

中文步骤

  1. Fix the upstream application to return a valid HTTP status line. For example, in a Python WSGI app, ensure the application returns a proper start line:
    def application(environ, start_response):
        status = '200 OK'
        headers = [('Content-Type', 'text/plain')]
        start_response(status, headers)
        return [b'Hello World']
    Check for missing or empty status strings in custom servers.
  2. Use nginx's proxy_pass with a rewrite to a different upstream that sanitizes responses, or place a reverse proxy like Varnish in front of the misbehaving upstream to normalize responses.

Dead Ends

Common approaches that don't work:

  1. Set proxy_http_version 1.1; 90% fail

    The error is about a malformed status line, not the HTTP version. Changing proxy version does not fix upstream's invalid output.

  2. Increase proxy_read_timeout 95% fail

    Timeout does not affect the format of the response; the upstream is responding, but with invalid data.

  3. Add proxy_buffering off; 92% fail

    Buffering affects how nginx reads the response body, not the status line parsing in the header.