Encountering the nginx 400 bad request request header or cookie too large error can be frustrating, especially when your website or API suddenly stops responding to legitimate client requests. This HTTP 400 status code indicates that the Nginx web server refuses to process a request because the header size—including cookies—exceeds the configured limit. In this guide, you will learn exactly why this error happens, how to diagnose it, and the step-by-step configuration changes needed to fix it safely.
What Does "Nginx 400 Bad Request: Request Header or Cookie Too Large" Mean?
When a browser or application sends an HTTP request to Nginx, that request includes headers. On top of that, headers carry metadata such as the user agent, referer, content type, authorization tokens, and cookies. Nginx allocates a fixed amount of memory to read these headers.
400 Bad Request Request Header or Cookie Too Large
This is a protective measure. So by limiting header size, Nginx guards the server against malformed requests, memory exhaustion, and certain types of denial-of-service attacks. The default limits are often conservative—commonly 1 KB for the main header buffer and 4 KB to 8 KB for larger header sets—so modern web applications that rely on heavy authentication cookies or custom headers can easily outgrow them.
Common Causes Behind the Error
Understanding the root cause helps you apply the right fix instead of blindly raising limits. The most frequent triggers include:
- Oversized authentication cookies: Single sign-on tokens, session data, or JWTs stored in cookies can grow beyond the default buffer.
- Excessive custom headers: Applications that inject dozens of custom