Home › Web & HTTP

400 Bad Request: Request Header Or Cookie Too Large (nginx) — how to fix

400 Bad Request
Request Header Or Cookie Too Large
nginx

Quick fix: As a user: clear cookies for that site (or try a private window). As the server owner: raise the limit in the http or server block, e.g. large_client_header_buffers 4 32k;, then sudo nginx -t && sudo systemctl reload nginx. Long term, stop storing large data in cookies.

What it means

nginx reads request headers into buffers. Each header line, and the request line, must fit into one buffer defined by large_client_header_buffers (default 4 8k: up to 4 buffers of 8 KB). If one header line, usually Cookie:, is larger than 8 KB, nginx returns 400 Request Header Or Cookie Too Large. (If the request URL itself is too long, the same directive produces 414 Request-URI Too Large.)

Cookies grow because every cookie for the domain, including those set by analytics, A/B testing, or auth libraries that store whole sessions or tokens, is sent with every request.

Fix 1 (users): clear cookies for the site

Fix 2 (server): raise the buffer size

In nginx.conf (http block) or the site's server block:

http {
    large_client_header_buffers 4 32k;
}

Test and reload:

sudo nginx -t && sudo systemctl reload nginx

Notes:

Fix 3: also raise limits behind nginx

If nginx is a reverse proxy, the backend may have its own limit and fail next with its own error:

The response-side counterpart (upstream sent too big header) is a different setting, proxy_buffer_size; see the related page.

Fix 4: make the cookies smaller

Raising limits only postpones the problem. Find what's large in the browser dev tools (Application → Cookies, Size column) or log it:

log_format cookies '$remote_addr "$http_cookie"';

Typical culprits and fixes:

Last updated 2026-11-28.