# client closed connection while reading response header from upstream

- **ID:** `nginx/client-closed-connection-while-reading-response`
- **Domain:** nginx
- **Category:** network_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

Client disconnects prematurely before nginx finishes reading the upstream response header, typically due to browser timeout or user cancellation.

## Version Compatibility

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

## Workarounds

1. **Set proxy_ignore_client_abort on; in the location block: proxy_ignore_client_abort on;** (85% success)
   ```
   Set proxy_ignore_client_abort on; in the location block: proxy_ignore_client_abort on;
   ```
2. **Reduce response generation time by optimizing upstream application or enabling caching: proxy_cache my_cache; proxy_cache_valid 200 1h;** (75% success)
   ```
   Reduce response generation time by optimizing upstream application or enabling caching: proxy_cache my_cache; proxy_cache_valid 200 1h;
   ```
3. **Increase client_header_timeout and client_body_timeout to prevent premature disconnection: client_header_timeout 60s; client_body_timeout 60s;** (70% success)
   ```
   Increase client_header_timeout and client_body_timeout to prevent premature disconnection: client_header_timeout 60s; client_body_timeout 60s;
   ```

## Dead Ends

- **** — The issue is client disconnection, not upstream timeout; high timeout may mask the problem but doesn't prevent it. (60% fail)
- **** — Keepalive settings affect connection reuse, not client disconnection during response reading. (80% fail)
- **** — Disabling buffering can increase memory usage and doesn't address the root cause of client disconnection. (70% fail)
