nginx.ccWeb server troubleshooting desk
Home / Errors / 502
502

Nginx 502: upstream sent too big header

Short answer

“upstream sent too big header” means the backend's response headers (usually many or large Set-Cookie headers, or a long Location) exceed proxy_buffer_size / fastcgi_buffer_size (one memory page, 4k or 8k, by default), so nginx returns 502. Raise the matching buffer size to 16k–32k and check why the app sends such headers.

Most common cause: Login or SSO callbacks set several large cookies at once.

Try this first: Reverse proxy (proxy_pass)

proxy_buffer_size 16k;
proxy_buffers 8 16k;
proxy_busy_buffers_size 32k;

Last verified: · against the official docs listed below · Sources

Typical log lines

upstream sent too big header while reading response header from upstream
upstream sent too big header while reading response header from upstream, client: 203.0.113.7, server: example.com, request: "POST /login HTTP/1.1", upstream: "fastcgi://unix:/run/php/php8.3-fpm.sock:"

Common causes

  1. Login or SSO callbacks set several large cookies at once.
  2. The app puts debug data or permission lists into headers.
  3. WordPress plugins or Magento admin pages send long Link / Set-Cookie headers.

Diagnosis commands

The upstream field shows proxy or fastcgi
#grep 'too big header' /var/log/nginx/error.log | tail -3
Measure header size bypassing nginx
#curl -s -D - -o /dev/null http://127.0.0.1:3000/login | wc -c

Fix configs

Reverse proxy (proxy_pass)

proxy_buffer_size 16k;
proxy_buffers 8 16k;
proxy_busy_buffers_size 32k;

PHP-FPM (fastcgi_pass)

fastcgi_buffer_size 32k;
fastcgi_buffers 16 16k;
fastcgi_busy_buffers_size 32k;

Run nginx -t first, then systemctl reload nginx.

Key facts and sources

  • proxy_buffer_size is used for the first part of the response (the headers) and defaults to one memory page: 4k or 8k. [nginx.org]
  • fastcgi_buffer_size plays the same role for FastCGI, also 4k or 8k by default. [nginx.org]

Checked against the linked pages on 2026-11-14; the official docs win if a newer nginx changes them.

FAQ

Any downside to bigger buffers?

A bit more memory per connection. 16k–32k is harmless for most sites; needing hundreds of KB means the app should change.

Why change busy_buffers_size too?

proxy_busy_buffers_size must be at least the larger of proxy_buffer_size and one proxy_buffers buffer, or nginx -t fails.

Fix it with a tool

Related errors

Sponsored slot (empty)
VPS / CDN recommendations may appear here later, labelled as affiliate links. There are no referral links today.