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

- **ID:** `nginx/upstream-sent-invalid-content-encoding`
- **Domain:** nginx
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 89%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| nginx/1.24.0 | active | — | — |
| nginx/1.22.1 | active | — | — |

## Workarounds

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.** (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.
   ```
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; }** (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; }
   ```
3. **Set proxy_set_header Accept-Encoding identity; to request uncompressed content from upstream.** (75% success)
   ```
   Set proxy_set_header Accept-Encoding identity; to request uncompressed content from upstream.
   ```

## Dead Ends

- **** — This only compresses responses from nginx to client, not upstream response handling. (85% fail)
- **** — This prevents upstream from sending compressed responses, but if upstream still sends Content-Encoding, the error persists. (70% fail)
- **** — The error is about header value validity, not size. (80% fail)
