VPS Tutorials
Nginx 400 Header or Cookie Too Large: identify the field and fix the limit
Find oversized cookies and request headers, distinguish request-body and upstream-response errors, adjust Nginx persistently and verify the complete login workflow.

A site that worked yesterday now shows 400 Bad Request followed by Request Header Or Cookie Too Large after login. A Cookie or another request-header field may exceed the limit at the receiving server. Visitors can compare a private window; site owners need to identify the oversized field and the layer rejecting it.
To regain access temporarily, clear cookies for this site and sign in again. If the problem returns, investigate the server and application. Increasing client_max_body_size changes the request-body limit for uploads and normally does not fix a request-header error.
Open the same full URL in a private window, initially signed out, then test after login. If that window works while your usual one fails, remove only this domain's cookies in the browser's site settings and reopen it. This signs you out and may remove a cart or preferences stored in cookies.
You do not need to erase data for every website. If login immediately triggers the error, tell the site owner the URL, time and the fact that it works before login. Clearing cookies shrinks the next request; it neither changes the server limit nor stops the application from producing large login data again.
| Error or log | Investigate first | Relevant change |
|---|---|---|
| 400 explicitly mentioning Header Or Cookie Too Large | Cookie, Authorization and other headers sent to Nginx | Request-header buffers and cookie/token size |
| 431 Request Header Fields Too Large | The proxy or application returning it | That layer's per-field or total-header limit |
| 414 URI Too Long | Path and query string | Shorter URL and request-line limits |
| 413 Request Entity Too Large | Upload or submitted request body | Upload endpoint and application body limits |
| 502 with upstream sent too big header | Response headers from the upstream, such as Set-Cookie | Upstream response and response-header buffering |
400 alone does not prove a cookie is too large. Malformed requests can also return 400. Use the actual error text and logs. A 431 can indicate an oversized individual field or total headers; see MDN's 431 reference. For uploads returning 413, use the Nginx, PHP and Cloudflare upload-limit guide.
Select the failed request under Network in browser developer tools. Check its URL, status and Request Headers, particularly Cookie, Authorization and long custom fields. Compare the same page before and after login rather than only testing the home page.
Several small cookies can form one large Cookie header. Cookies with the same name but different Domain or Path values may also be sent together. document.cookie misses HttpOnly cookies, so inspect the request the browser actually sends.
On the VPS, identify the version, effective configuration and log locations:
nginx -v
sudo nginx -T
sudo tail -n 100 /var/log/nginx/error.log
Replace log paths as needed. nginx -T expands the configuration and shows its source files, helping you locate the active http, server and duplicated settings. Record field names and lengths; redact cookies, tokens and configuration credentials before sharing output.
Relevant messages may contain client sent too large header, but the configured log level may omit them. Their absence does not rule this out. If the access log includes $upstream_status, compare its timestamp with backend logs to determine whether the application received the request. Nginx branding on an error page does not identify which proxy in the chain rejected it.
Nginx documents these defaults:
client_header_buffer_size 1k;
large_client_header_buffers 4 8k;
1k is the initial buffer used to read headers. Larger buffers can be allocated when needed; it is not a universal 1 KB header ceiling. 4 8k permits up to four large buffers of 8 KB each.
For HTTP/1.1, an individual header field must fit in one large buffer. An over-8-KB Cookie field does not gain a contiguous 64-KB buffer merely by selecting 8 8k. The directive reference also distinguishes an oversized request line returning 414 from an oversized header field returning 400.
The source article reports an isolated local test with Nginx 1.19.6 and HTTP/1.1. Five simulated cookies, each containing 1,800 ASCII characters, produced a 9,023-byte Cookie value. The endpoint normally returned 204:
| Buffer configuration | Without cookies | With the 9,023-byte simulated Cookie |
|---|---|---|
4 8k | 204 | 400 with the oversized-cookie message |
8 8k | 204 | 400 again |
4 16k | 204 | 204; the header was accepted |
This historical test illustrates HTTP/1.1 buffer semantics. Use a maintained Nginx release in production. A 204 demonstrates acceptance of that simulated request, not successful real authentication. Test HTTP/2 and HTTP/3 against the version and protocol you actually use.
If legitimate requests exceed the current limit, increasing each large buffer from 8 KB to 16 KB can be a starting point. Continue investigating why the application needs so much data. Choose the final limit from actual field lengths, traffic and limits elsewhere in the proxy chain.
The following belongs inside the existing http block. Edit the original settings rather than adding another http block:
client_header_buffer_size 1k;
large_client_header_buffers 4 16k;
Both directives support only http and server, not location. At http, sites inherit them unless they override the values. Assess other sites on a shared instance. For an individual server, also check the default virtual host, SNI, Host and the stage at which the headers are processed; see virtual-server selection.
Back up the actual file before editing. This example uses /etc/nginx/nginx.conf; substitute the site-file path when appropriate and choose a fresh backup name:
sudo cp -a /etc/nginx/nginx.conf /etc/nginx/nginx.conf.header-backup-20261109
After saving the change, check configuration:
sudo nginx -t
Only after that succeeds, reload:
sudo systemctl reload nginx
To roll back, restore the backup, check it and then reload. Large buffers are allocated on demand, but many simultaneous large requests still increase memory use. Do not copy enormous values such as 16 128k without a justified requirement.
For Nginx in Docker, edit the persistent host-side configuration mounted into the container. With a Compose service named nginx, check before reloading:
docker compose exec nginx nginx -t
docker compose exec nginx nginx -s reload
Use your actual service name. Changes to a temporary container file can disappear on recreation. BaoTa, 1Panel and Nginx Proxy Manager users should use the panel's persistent configuration interface and verify that its insertion context permits these directives.
A larger buffer does not justify indefinitely growing cookies. Common causes include entire user profiles, permission lists or carts in cookies; tokens containing many roles; and old plugins leaving same-name cookies on different paths.
Remove unnecessary data or, where the application supports it, use a shorter session identifier with details stored server-side. Deleting obsolete cookies requires matching their original Domain and Path. Verify logout, renewal and authorization after changing session handling.
In a browser → CDN → Nginx → application chain, every layer may impose a limit. Increasing the origin limit cannot fix rejection by the CDN. Conversely, Nginx may accept the request while the backend returns 431. Trace the same failed request through each layer.
If the log instead says upstream sent too big header, Nginx is failing while reading an upstream response, possibly containing large Set-Cookie fields. Investigate that response and proxy_buffer_size, rather than increasing client-header buffers; see proxy_buffer_size.
Retest the original failing window and retain the failed request for comparison. In a clean window, log in, refresh an authenticated page, log out and log in again. Confirm stable header sizes, disappearance of the failure and correct backend requests. An unauthenticated curl request to the home page does not reproduce the original problem.
Avoid copying http2_max_field_size and http2_max_header_size from old HTTP/2 tutorials. Both have been obsolete since 1.19.7; the documented replacement is large_client_header_buffers. See the HTTP/2 module reference and retest with your real protocol.
For related failures: