PHP error guide

nginx upstream sent too big header: meaning and fix

Error summary

Reduce cookie/header payload first; tune FastCGI buffers only after measuring. PHP emits response headers larger than configured FastCGI buffers, often oversized cookies.

What it means

Reduce cookie/header payload first; tune FastCGI buffers only after measuring. PHP emits response headers larger than configured FastCGI buffers, often oversized cookies.

What the error means

This message means that PHP emits response headers larger than configured FastCGI buffers, often oversized cookies. The exact signature distinguishes nginx upstream sent too big header from a generic application failure.

Why PHP produces it

The engine or service reports “nginx upstream sent too big header” because its required precondition was not met. Reduce cookie/header payload first; tune FastCGI buffers only after measuring.

PHP version notes

The nginx upstream sent too big header wording here is based on Current PHP-FPM, Apache 2.4, or nginx; punctuation and exception class names can differ on older branches or vendor builds.

Most common causes

  • The immediate input or configuration reaches the specific condition: PHP emits response headers larger than configured FastCGI buffers, often oversized cookies
  • The code path assumes the prerequisite for nginx upstream sent too big header has already been satisfied.
  • For nginx upstream sent too big header, development and production differ in version, extension, permissions, paths, or service configuration.
  • An earlier operation returned an unchecked value that is consumed by the line reporting nginx upstream sent too big header.

Minimal examples

BAD — reproduces the problem

php
setcookie("state", str_repeat("x", 20000));

FIXED — safer pattern

php
setcookie("session", $shortOpaqueId, ["httponly"=>true, "secure"=>true]);

Step-by-step diagnosis

  1. Copy the complete “upstream sent too big header while reading response header from upstream” text and retain the first application stack frame.
  2. Reproduce nginx upstream sent too big header in the same SAPI and environment listed for this page.
  3. Before changing nginx upstream sent too big header, inspect the preceding value or directive and verify its type, path, version, and permissions.
  4. Apply the narrow correction—reduce cookie/header payload first; tune FastCGI buffers only after measuring—then repeat the original request once.

Fixes

Correct the failing prerequisite

Reduce cookie/header payload first; tune FastCGI buffers only after measuring

php
setcookie("session", $shortOpaqueId, ["httponly"=>true, "secure"=>true]);

Fail explicitly at the boundary

Validate the condition before the operation that emits nginx upstream sent too big header, and log a safe diagnostic without credentials or full production paths.

Common mistakes when fixing it

  • Suppressing nginx upstream sent too big header instead of correcting its upstream condition.
  • Testing nginx upstream sent too big header only with the CLI binary when the failing request runs under FPM or Apache.
  • Changing a global setting for nginx upstream sent too big header before confirming the site-specific effective configuration.

How to prevent it

  • Add a focused test that exercises the boundary responsible for nginx upstream sent too big header.
  • Keep runtime versions, extensions, configuration, and deploy artifacts affecting nginx upstream sent too big header reproducible.
  • Validate external data and service return values before they can trigger nginx upstream sent too big header.

Web server / environment notes

fpm, nginx, linux. The failure occurs where pHP emits response headers larger than configured FastCGI buffers, often oversized cookies

Tags: fpm,nginx,linux

Categories