nginx protocol_error ai_generated true

upstream sent invalid Connection header while reading response header from upstream

ID: nginx/upstream-sent-invalid-connection-header

Also available as: JSON · Markdown
90%Fix Rate
85%Confidence
1Evidence
2024-06-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx 1.24.0 active
nginx 1.25.3 active
nginx 1.26.0 active

Root Cause

Upstream server returns a malformed or non-compliant 'Connection' header (e.g., multiple values, invalid token) that nginx rejects.

generic

Official Documentation

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

Workarounds

  1. 90% success Use proxy_ignore_headers to ignore the Connection header from upstream: location / { proxy_pass http://upstream; proxy_ignore_headers Connection; }
    Use proxy_ignore_headers to ignore the Connection header from upstream:
      location / {
          proxy_pass http://upstream;
          proxy_ignore_headers Connection;
      }
  2. 95% success Fix the upstream application to emit a valid Connection header (e.g., 'close' or 'keep-alive' only, no duplicates). For example, in a Node.js app: res.setHeader('Connection', 'keep-alive'); // Remove any duplicate or malformed Connection headers
    Fix the upstream application to emit a valid Connection header (e.g., 'close' or 'keep-alive' only, no duplicates). For example, in a Node.js app:
      res.setHeader('Connection', 'keep-alive');
      // Remove any duplicate or malformed Connection headers

中文步骤

  1. Use proxy_ignore_headers to ignore the Connection header from upstream:
      location / {
          proxy_pass http://upstream;
          proxy_ignore_headers Connection;
      }
  2. Fix the upstream application to emit a valid Connection header (e.g., 'close' or 'keep-alive' only, no duplicates). For example, in a Node.js app:
      res.setHeader('Connection', 'keep-alive');
      // Remove any duplicate or malformed Connection headers

Dead Ends

Common approaches that don't work:

  1. Add proxy_set_header Connection ''; 80% fail

    This only affects request headers sent to upstream, not response headers from upstream.

  2. Clear nginx cache 100% fail

    Caching does not cause or fix header validation issues.

  3. Upgrade nginx to latest version 60% fail

    The issue is usually in the upstream application, not nginx itself.