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

Nginx 400 Request Header Or Cookie Too Large: fix

Short answer

400 “Request Header Or Cookie Too Large” means one request header line, usually Cookie, is larger than a single large_client_header_buffers buffer (8k by default). Clear the site's cookies to confirm, then raise it to 16k or 32k in http {}.

Most common cause: Cookies pile up: analytics, A/B testing and ad scripts each add some, or the app stores a whole session / JWT in a cookie.

Try this first: Raise the header buffers at http level

http {
    large_client_header_buffers 4 32k;   # default 4 8k
}

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

Typical log lines

client sent too long header line: "Cookie: …" while reading client request headers
client sent too long URI while reading client request line

Common causes

  1. Cookies pile up: analytics, A/B testing and ad scripts each add some, or the app stores a whole session / JWT in a cookie.
  2. Single sign-on sends a very long Authorization header.
  3. A very long query string gives 414 Request-URI Too Large instead; the same directive controls it.
  4. Raised only in a non-default server: header parsing can start before the server is chosen, so the default server's value may apply.

Diagnosis commands

Logged at info level; invisible if error_log is set above info
#grep 'too long header line' /var/log/nginx/error.log | tail -3
Reproduce with a 12 KB cookie
#curl -s -o /dev/null -w '%{http_code}\n' -H "Cookie: big=$(head -c 12000 /dev/zero | tr '\0' x)" https://example.com/
Current value and where it is set
#nginx -T 2>/dev/null | grep -n large_client_header_buffers

Fix configs

Raise the header buffers at http level

http {
    large_client_header_buffers 4 32k;   # default 4 8k
}

App side: keep big data out of cookies

# keep session data server-side (Redis / database); the cookie only holds the session ID
# drop unused analytics and A/B-testing cookies

Run nginx -t first, then systemctl reload nginx.

Key facts and sources

  • large_client_header_buffers defaults to 4 8k: a header line larger than one buffer returns 400, an oversized request line returns 414. [nginx.org]
  • When set at server level, the default server's value can be used. [nginx.org]

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

FAQ

Why do only some users see it?

Only browsers that accumulated many cookies exceed 8k; a private window usually works, which confirms it is the cookies.

How large should it be?

16k or 32k covers almost every site. Going higher only hides an app that stores too much in cookies and costs memory per connection.

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.