# upstream sent invalid header while reading response header from upstream

- **ID:** `nginx/upstream-sent-invalid-header`
- **Domain:** nginx
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

Upstream server returned a malformed or invalid HTTP header that nginx cannot parse, often due to a backend application crash or misconfiguration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| nginx 1.18.0 | active | — | — |
| nginx 1.20.2 | active | — | — |
| nginx 1.24.0 | active | — | — |

## Workarounds

1. **Check upstream application logs for errors (e.g., PHP-FPM logs, uWSGI logs). Fix the application code that sends malformed headers.** (85% success)
   ```
   Check upstream application logs for errors (e.g., PHP-FPM logs, uWSGI logs). Fix the application code that sends malformed headers.
   ```
2. **Add a custom error page or proxy_intercept_errors on; for example:
server {
    proxy_intercept_errors on;
    error_page 502 /502.html;
}
This hides the error from clients but does not fix the root cause.** (30% success)
   ```
   Add a custom error page or proxy_intercept_errors on; for example:
server {
    proxy_intercept_errors on;
    error_page 502 /502.html;
}
This hides the error from clients but does not fix the root cause.
   ```
3. **Configure nginx to ignore invalid headers by setting 'proxy_ignore_headers X-Accel-Redirect;' if the invalid header is non-critical, but prefer fixing upstream.** (50% success)
   ```
   Configure nginx to ignore invalid headers by setting 'proxy_ignore_headers X-Accel-Redirect;' if the invalid header is non-critical, but prefer fixing upstream.
   ```

## Dead Ends

- **** — The error is not about buffer size but about header validity; increasing buffers masks the issue but backend still sends invalid data. (65% fail)
- **** — Restarting nginx does not fix the upstream application that generates invalid headers. (80% fail)
- **** — Disabling buffering may change behavior but does not correct invalid headers from upstream. (70% fail)
