# Nginx: [error] upstream prematurely closed connection while reading response header from upstream

**Code:** `upstream prematurely closed connection while reading response header` · **Category:** Nginx / Apache · **Seen on:** Nginx, Linux

The backend ended the connection before sending a complete response header.

## Meaning

Usually the app/PHP-FPM worker crashed (fatal error, segfault, memory limit) or exited, or a proxy timeout/keepalive race closed the socket. Check PHP-FPM/app logs for fatal errors, `request_terminate_timeout`, `max_execution_time` and OOM kills.

## Common causes

- PHP fatal/segfault or exit() mid-request
- Worker killed by OOM or timeout (`request_terminate_timeout`)
- Backend keepalive closed the idle connection (race)
- Wrong protocol (HTTP to a TLS/FastCGI port)
- App crashed on large payloads

## Quick fix

1. Read the app/PHP-FPM error log for the crash
2. Align timeouts; disable/adjust backend keepalive
3. Check `dmesg` for OOM kills

## Detailed fix by platform

### Linux

1. `sudo journalctl -u php8.3-fpm --since "10 min ago" | tail -30`

## How to diagnose

1. **Backend log** — Fatal or crash?
2. **Timeouts** — request_terminate_timeout?
3. **Protocol** — Correct?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nginx-apache/nginx-upstream-prematurely-closed-connection)
