client sent too long header line
- Cause
- A request header field is larger than one
large_client_header_buffersbuffer
Fix an nginx 400 Bad Request: oversized headers or cookies, invalid header names, bad Host values and plain HTTP sent to an HTTPS port, with config and log lines.
In nginx, a 400 Bad Request means nginx rejected the request before it reached your app. The usual causes are a request header or cookie larger than large_client_header_buffers allows, a header line nginx cannot parse, an invalid Host header, or plain HTTP sent to an HTTPS port. The cause is logged at info level, so the default error log can look empty.
Four quick questions, then a straight answer.
From your answers, this is quietly costing you traffic and nobody has the hours to chase it. Scaplet finds every affected page, drafts the fixes and tracks how AI answers mention you.
A data platform shipped 46 fixes without a ticket.
This looks handled. Re-check after a redesign, a migration or a big content push; that is when it breaks.
Your site is small and you have the time. Work through the steps on this page, starting with the pages that get the most traffic.
client sent too long header linelarge_client_header_buffers bufferclient sent invalid header lineignore_invalid_headers on (the default), a field with an invalid name is logged with this message but skipped, not rejectedclient sent invalid host headerclient sent plain HTTP request to HTTPS porthttp:// against a port configured with sslThe catch: nginx logs most of these rejections at the info level, and the default error_log level is error, so a 400 can leave nothing in the log. Raise the level for a short test, reproduce the request, and set it back.
# Default is: error_log logs/error.log error;
error_log /var/log/nginx/error.log info;large_client_header_buffers (default 4 8k) and client_header_buffer_size (default 1k)client sent invalid header line in the logunderscores_in_headers (default off) and ignore_invalid_headers (default on)ignore_invalid_headers, so the app never sees them. Rename the header to use hyphens, or set underscores_in_headers on if you must keep itlisten line with ssl and the URL the client useshttps://, or add a separate port 80 server block that redirectsHost the client or proxy sendsproxy_set_header Host linecurlcurl sendshttp {
client_header_buffer_size 4k;
large_client_header_buffers 4 16k; # number and size of buffers
}nginx's own page for an oversized header or cookie reads "Request Header Or Cookie Too Large" under a "400 Bad Request" heading. If you see that text, the buffer settings above are the first thing to check. RFC 6585 defines 431 for this case, but nginx documents a 400 for an oversized header field, so a CDN or another server in front may show 431 instead; see 431 Request Header Fields Too Large.
A 9,000-byte header value is larger than the 8k default buffer, so that request should return 400 until you raise the limit. After the change, the same command should reach your app. Google reads 4xx responses as client errors; the effect on crawling is covered on 4xx errors.
# See the status and body nginx returns
curl -sS -i https://example.com/ -H "X-Test: $(head -c 9000 /dev/zero | tr '\0' a)"
# Validate the config, then reload
sudo nginx -t && sudo nginx -s reload4 questions people ask next, answered from the sources on this page.
Set error_log to info for a short test, repeat the request, and read the log line. Then fix what it names: raise large_client_header_buffers for oversized headers or cookies, use https for an HTTPS port, or correct the Host header.
Increase large_client_header_buffers (the default is 4 8k) or clear the large cookie. A single request header field cannot exceed the size of one buffer, so raise the size value, not only the number.
RFC 9110 lists malformed request syntax, invalid message framing and deceptive request routing as examples of client errors that lead to a 400. In nginx the common triggers are oversized headers, a header line it cannot parse, a bad Host header and plain HTTP sent to an HTTPS port.
nginx logs these rejections at the info level, and the default level is error. Set error_log to info, reload, and repeat the request.
Run the free audit, then approve the fixes. Every change can be undone.