Skip to content
Log In Sign Up info@muvcloud.com

What a 431 Error Means

431 Request Header Fields Too Large says the request headers, all together or one of them, are over the server's limit. The browser sends every cookie for a site in one Cookie header with each request, so a site that sets many or large cookies eventually hits that limit. A very long Referer or authorization header can do the same. Other codes are listed in HTTP status codes explained.

If You See It on Someone Else's Site

  • Clear the site's cookies: in your browser's settings, delete cookies and site data for that site only, then reload.
  • Try a private window: it starts with no cookies; if the page loads there, cookies were the cause.
  • On a development machine: many local projects on localhost share one cookie jar. Clearing cookies for localhost often fixes a 431 from a development server.

Find the Oversized Header

Open the browser's developer tools, select the failing request in the network view, and look at the request headers, then at the stored cookies for the site. Reproduce it from a terminal with a large made-up cookie:

curl -I -H "Cookie: test=$(head -c 20000 /dev/zero | tr '\0' a)" http://127.0.0.1:3000/

If this returns 431 and a request without the cookie works, header size is confirmed.

Node.js Applications

Node.js is a common source of a 431: its HTTP server answers with 431 when the request headers exceed its limit, 16 KiB by default in current versions. Raise it at start-up:

node --max-http-header-size=32768 server.js

Or set it for one server in code:

const server = http.createServer({ maxHeaderSize: 32768 }, handler);

The value is in bytes. Raise it in steps, and only as far as you need.

Nginx

Nginx answers oversized headers with a 400 page titled "Request Header Or Cookie Too Large", not with 431. The limit is set by large_client_header_buffers (number and size, default 4 8k), in the http or server block:

large_client_header_buffers 4 16k;

Each single header line must fit in one buffer. Set at server level, the value from the default server can apply, so the http block is the safer place. Run sudo nginx -t and reload.

Apache

Apache also answers with 400, noting that a request header field exceeds the server limit. The directive LimitRequestFieldSize sets the largest single header in bytes (default 8190), and LimitRequestFields the number of headers (default 100):

LimitRequestFieldSize 16380

Put it in the server configuration; with name-based virtual hosts, Apache takes the value from the first virtual host for that address and port. Check with sudo apachectl configtest, and reload Apache.

Proxies in Between

Every hop applies its own limit. With Nginx in front of a Node.js application, raising the Node.js limit does nothing if Nginx rejects the request first, and the other way round. Raise the limit on every hop the request passes, starting with the one that sends the error: a 431 page comes from the application, a 400 page with the Nginx footer from Nginx.

Fix the Cause: Smaller Cookies

  • Store data on the server: keep a short session ID in the cookie and the data in the session store or database.
  • Remove old cookies: expire cookies the site no longer uses.
  • Limit cookie scope: a cookie set for the whole domain is sent to every subdomain too.
  • Review tracking scripts: analytics and marketing tags often set many cookies.

Confirm the Fix

curl -I https://example.com/

Repeat the large-cookie test from above against the site; it should now return 200 up to the size you allowed. For a server that answers 400 or other errors after the change, see 500 Internal Server Error and 429 Too Many Requests.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations