# upstream sent invalid status line while reading response header from upstream

- **ID:** `nginx/upstream-sent-invalid-status-line`
- **Domain:** nginx
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 87%

## Root Cause

Upstream server returned an HTTP status line that does not conform to RFC 7230 (e.g., missing HTTP version, malformed status code).

## Version Compatibility

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

## Workarounds

1. **Fix upstream server to return valid HTTP status line (e.g., in Python: ensure response starts with 'HTTP/1.1 200 OK\r\n'). Example using Flask: return 'OK', 200, {'Content-Type': 'text/plain'}** (95% success)
   ```
   Fix upstream server to return valid HTTP status line (e.g., in Python: ensure response starts with 'HTTP/1.1 200 OK\r\n'). Example using Flask: return 'OK', 200, {'Content-Type': 'text/plain'}
   ```
2. **Use a custom upstream module or script to sanitize response before nginx processes it (e.g., using lua-nginx-module: content_by_lua_block { ngx.say('OK') })** (70% success)
   ```
   Use a custom upstream module or script to sanitize response before nginx processes it (e.g., using lua-nginx-module: content_by_lua_block { ngx.say('OK') })
   ```
3. **Add proxy_http_version 1.0; to force HTTP/1.0 and expect simpler status line.** (75% success)
   ```
   Add proxy_http_version 1.0; to force HTTP/1.0 and expect simpler status line.
   ```

## Dead Ends

- **** — Trailing slash affects URI normalization, not the status line format from upstream. (80% fail)
- **** — Buffering does not affect header parsing; nginx always parses the status line. (85% fail)
- **** — This clears response headers, not the status line itself. (90% fail)
