nginx protocol_error ai_generated true

upstream sent invalid content-encoding while reading response header from upstream

ID: nginx/upstream-sent-invalid-content-encoding

Also available as: JSON · Markdown · 中文
89%Fix Rate
83%Confidence
1Evidence
2024-05-18First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
nginx/1.24.0 active
nginx/1.22.1 active

Root Cause

Upstream server returned a Content-Encoding header with an unsupported or malformed value (e.g., 'gzip;q=1.0' instead of 'gzip'), causing nginx to fail decompression.

generic

中文

上游服务器返回了不受支持或格式错误的 Content-Encoding 头(例如 'gzip;q=1.0' 而非 'gzip'),导致 nginx 解压缩失败。

Official Documentation

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

Workarounds

  1. 95% success Fix upstream server to return valid Content-Encoding (e.g., in PHP: header('Content-Encoding: gzip'); not 'gzip;q=1.0'). For Apache backend, ensure mod_deflate uses correct header.
    Fix upstream server to return valid Content-Encoding (e.g., in PHP: header('Content-Encoding: gzip'); not 'gzip;q=1.0'). For Apache backend, ensure mod_deflate uses correct header.
  2. 80% success Add proxy_ignore_headers Content-Encoding; in nginx config to ignore upstream encoding and treat response as uncompressed. Example: location / { proxy_pass http://backend; proxy_ignore_headers Content-Encoding; }
    Add proxy_ignore_headers Content-Encoding; in nginx config to ignore upstream encoding and treat response as uncompressed. Example: location / { proxy_pass http://backend; proxy_ignore_headers Content-Encoding; }
  3. 75% success Set proxy_set_header Accept-Encoding identity; to request uncompressed content from upstream.
    Set proxy_set_header Accept-Encoding identity; to request uncompressed content from upstream.

中文步骤

  1. Fix upstream server to return valid Content-Encoding (e.g., in PHP: header('Content-Encoding: gzip'); not 'gzip;q=1.0'). For Apache backend, ensure mod_deflate uses correct header.
  2. Add proxy_ignore_headers Content-Encoding; in nginx config to ignore upstream encoding and treat response as uncompressed. Example: location / { proxy_pass http://backend; proxy_ignore_headers Content-Encoding; }
  3. Set proxy_set_header Accept-Encoding identity; to request uncompressed content from upstream.

Dead Ends

Common approaches that don't work:

  1. 85% fail

    This only compresses responses from nginx to client, not upstream response handling.

  2. 70% fail

    This prevents upstream from sending compressed responses, but if upstream still sends Content-Encoding, the error persists.

  3. 80% fail

    The error is about header value validity, not size.