Free auditStart free
GuideError · HTTP status codes

400 Bad Request in nginx

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.

4 min
read
7
sources
Oct 24, 2026
updated
Scaplet Editorial Team
author
The short answer

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.

  1. Why nginx returns a 400
  2. Causes specific to nginx and the fix for each
  3. Reproduce it and verify the fix
30-second check

Where does your site stand?

Four quick questions, then a straight answer.

1/4Have you checked your own site for this?
Summarize this page withChatGPTClaudePerplexityGoogleAI Mode
02nginx 400 causes

Causes specific to nginx and the fix for each

Cause

Header or cookie too large

Where to look
large_client_header_buffers (default 4 8k) and client_header_buffer_size (default 1k)
Fix
Raise the buffer size, or shrink the cookie. A request header field cannot exceed the size of one buffer, or nginx returns 400. A request line over one buffer returns 414 instead
Cause

Header line nginx cannot parse

Where to look
client sent invalid header line in the log
Fix
Find the client or proxy that sends the malformed line and fix it
Cause

Header with an underscore is missing, not rejected

Where to look
underscores_in_headers (default off) and ignore_invalid_headers (default on)
Fix
With underscores disabled, such fields are marked invalid and become subject to 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 it
Cause

Plain HTTP sent to an HTTPS port

Where to look
The listen line with ssl and the URL the client uses
Fix
Use https://, or add a separate port 80 server block that redirects
Cause

Invalid Host header

Where to look
The Host the client or proxy sends
Fix
Fix the client or the proxy's proxy_set_header Host line
Cause

Bad request from a proxy in front of nginx

Where to look
Whether the same request works straight to nginx with curl
Fix
Compare the headers the proxy adds with the ones curl sends
Raise header buffers for large cookies
http {
    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.

03Check it

Reproduce it and verify the fix

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.

Test from the command line
# 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 reload
Sources · 7

Every fact, linked and dated.

Official docs first. The date is when we last opened each page.
  • rfc-editor.org
  • nginx.org
  • github.com
  • google.com
  1. 01RFC 9110: HTTP Semanticsrfc-editor.org · checked 2026-10-25
  2. 02nginx: ngx_http_core_modulenginx.org · checked 2026-10-25
  3. 03nginx: core functionality (error_log)nginx.org · checked 2026-10-25
  4. 04nginx source: src/http/ngx_http_request.cgithub.com · checked 2026-10-25
  5. 05nginx source: src/http/ngx_http_special_response.cgithub.com · checked 2026-10-25
  6. 06RFC 6585: Additional HTTP Status Codesrfc-editor.org · checked 2026-10-25
  7. 07How HTTP status codes affect Google's crawlersdevelopers.google.com · checked 2026-10-25
Questions

Asked a lot.

4 questions people ask next, answered from the sources on this page.

01How do I fix 400 Bad Request in nginx?

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.

02How do I fix "Request Header Or Cookie Too Large" in nginx?

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.

03What causes a 400 Bad Request error?

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.

04Why is my nginx error log empty when users get a 400?

nginx logs these rejections at the info level, and the default level is error. Set error_log to info, reload, and repeat the request.

Free · 2 minutes

Tools point. Agencies advise. This one ships.

Run the free audit, then approve the fixes. Every change can be undone.

Free, no card60 secondsNobody will call you
  • 46 fixes shipped without a ticket Brightpipe
  • 0→7 ChatGPT citations in six weeks Paylane