nginx protocol_error ai_generated partial

上游服务器在读取响应头时发送了无效的服务器名称

upstream sent invalid server name while reading response header from upstream

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

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

版本兼容性

版本状态引入弃用备注
nginx 1.24.0 active — — —
nginx 1.22.1 active — — —
nginx 1.20.2 active — — —
nginx 1.18.0 active — — —

根因分析

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

English

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

generic

官方文档

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

解决方案

  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 }'

无效尝试

常见但无效的做法:

  1. 80% 失败

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

  2. 90% 失败

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

  3. 95% 失败

    proxy_buffering controls response body buffering, not header validation.