# upstream sent invalid server name while reading response header from upstream

- **ID:** `nginx/upstream-sent-invalid-server-name`
- **Domain:** nginx
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The upstream server responded with an HTTP header containing a malformed or excessively long server name that violates HTTP specifications.

## Version Compatibility

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

## Workarounds

1. **Add 'proxy_ignore_headers Server;' in the location block to make nginx ignore the Server header from upstream, preventing the error.** (85% success)
   ```
   Add 'proxy_ignore_headers Server;' in the location block to make nginx ignore the Server header from upstream, preventing the error.
   ```
2. **Fix the upstream application to send a valid Server header (e.g., 'Server: Apache/2.4.41 (Unix)') without control characters or excessive length (> 255 characters).** (90% success)
   ```
   Fix the upstream application to send a valid Server header (e.g., 'Server: Apache/2.4.41 (Unix)') without control characters or excessive length (> 255 characters).
   ```
3. **Use a custom header filter with lua (if OpenResty) to sanitize the Server header: 'header_filter_by_lua_block { ngx.header["Server"] = nil }'** (75% success)
   ```
   Use a custom header filter with lua (if OpenResty) to sanitize the Server header: 'header_filter_by_lua_block { ngx.header["Server"] = nil }'
   ```

## Dead Ends

- **** — The error is about header value validity, not buffer capacity. (80% fail)
- **** — The root cause is the upstream server generating invalid headers; changing the target doesn't help. (90% fail)
- **** — proxy_buffering controls response body buffering, not header validation. (95% fail)
