nginx
protocol_error
ai_generated
partial
upstream sent invalid status line while reading response header from upstream: "HTTP/1.1 200 OK\r\n" (extra characters)
ID: nginx/upstream-sent-invalid-status-line-while-reading-response-header
85%Fix Rate
82%Confidence
1Evidence
2025-08-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| nginx 1.24.0 | active | — | — | — |
| nginx 1.25.3 | active | — | — | — |
| nginx 1.26.0 | active | — | — | — |
Root Cause
Upstream server sends a response with malformed status line, such as extra spaces, invalid characters, or non-standard HTTP version.
genericOfficial Documentation
https://nginx.org/en/docs/http/ngx_http_proxy_module.htmlWorkarounds
-
30% success Use a custom nginx module or Lua to sanitize upstream response. Example with lua-nginx-module: location / { rewrite_by_lua_block { -- This is a placeholder; actual sanitization would require body_filter_by_lua } body_filter_by_lua ' -- If you can modify headers, but status line is not easily modifiable in Lua -- Better to fix upstream '; proxy_pass http://upstream; }
Use a custom nginx module or Lua to sanitize upstream response. Example with lua-nginx-module: location / { rewrite_by_lua_block { -- This is a placeholder; actual sanitization would require body_filter_by_lua } body_filter_by_lua ' -- If you can modify headers, but status line is not easily modifiable in Lua -- Better to fix upstream '; proxy_pass http://upstream; } -
95% success Fix the upstream application to emit a valid HTTP status line. For example, in a Python server: # Ensure the response line is exactly "HTTP/1.1 200 OK\r\n" response = b"HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nhello" # Avoid extra characters or spaces after the status line
Fix the upstream application to emit a valid HTTP status line. For example, in a Python server: # Ensure the response line is exactly "HTTP/1.1 200 OK\r\n" response = b"HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nhello" # Avoid extra characters or spaces after the status line
中文步骤
Use a custom nginx module or Lua to sanitize upstream response. Example with lua-nginx-module: location / { rewrite_by_lua_block { -- This is a placeholder; actual sanitization would require body_filter_by_lua } body_filter_by_lua ' -- If you can modify headers, but status line is not easily modifiable in Lua -- Better to fix upstream '; proxy_pass http://upstream; }Fix the upstream application to emit a valid HTTP status line. For example, in a Python server: # Ensure the response line is exactly "HTTP/1.1 200 OK\r\n" response = b"HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nhello" # Avoid extra characters or spaces after the status line
Dead Ends
Common approaches that don't work:
-
Add proxy_set_header Host $host;
100% fail
This sets request headers, not response validation.
-
Increase proxy_read_timeout
100% fail
Timeout does not fix malformed response line.
-
Restart nginx
100% fail
Restarting does not change upstream behavior.