nginx protocol_error ai_generated partial

upstream sent invalid server name while reading response header from upstream

ID: nginx/upstream-sent-invalid-server-name

Also available as: JSON · Markdown · 中文
80%Fix Rate
85%Confidence
1Evidence
2023-11-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx 1.24.0 active
nginx 1.22.1 active
nginx 1.20.2 active
nginx 1.18.0 active

Root Cause

The upstream server responded with an HTTP header containing a malformed or excessively long server name that violates HTTP specifications.

generic

中文

上游服务器响应的 HTTP 头部包含格式错误或过长的服务器名称,违反了 HTTP 规范。

Official Documentation

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

Workarounds

  1. 85% success Add 'proxy_ignore_headers Server;' in the location block to make nginx ignore the Server header from upstream, preventing the error.
    Add 'proxy_ignore_headers Server;' in the location block to make nginx ignore the Server header from upstream, preventing the error.
  2. 90% success Fix the upstream application to send a valid Server header (e.g., 'Server: Apache/2.4.41 (Unix)') without control characters or excessive length (> 255 characters).
    Fix the upstream application to send a valid Server header (e.g., 'Server: Apache/2.4.41 (Unix)') without control characters or excessive length (> 255 characters).
  3. 75% success Use a custom header filter with lua (if OpenResty) to sanitize the Server header: 'header_filter_by_lua_block { ngx.header["Server"] = nil }'
    Use a custom header filter with lua (if OpenResty) to sanitize the Server header: 'header_filter_by_lua_block { ngx.header["Server"] = nil }'

中文步骤

  1. Add 'proxy_ignore_headers Server;' in the location block to make nginx ignore the Server header from upstream, preventing the error.
  2. Fix the upstream application to send a valid Server header (e.g., 'Server: Apache/2.4.41 (Unix)') without control characters or excessive length (> 255 characters).
  3. Use a custom header filter with lua (if OpenResty) to sanitize the Server header: 'header_filter_by_lua_block { ngx.header["Server"] = nil }'

Dead Ends

Common approaches that don't work:

  1. 80% fail

    The error is about header value validity, not buffer capacity.

  2. 90% fail

    The root cause is the upstream server generating invalid headers; changing the target doesn't help.

  3. 95% fail

    proxy_buffering controls response body buffering, not header validation.