# 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.

Canonical: https://scaplet.com/errors/http/400/nginx

Guide Error · HTTP status codes

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

400 4xx · Client error

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](#why-nginx-returns-a-400)
2. [Causes specific to nginx and the fix for each](#causes-specific-to-nginx-and-the-fix-for-each)
3. [Reproduce it and verify the fix](#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 with [ChatGPT](https://chatgpt.com/?hints=search&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F400%2Fnginx%20(%22400%20Bad%20Request%20in%20nginx%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Claude](https://claude.ai/new?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F400%2Fnginx%20(%22400%20Bad%20Request%20in%20nginx%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [Perplexity](https://www.perplexity.ai/search?q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F400%2Fnginx%20(%22400%20Bad%20Request%20in%20nginx%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.) [![Google](/logos/ai/google-color.svg)AI Mode](https://www.google.com/search?udm=50&q=Summarize%20https%3A%2F%2Fscaplet.com%2Ferrors%2Fhttp%2F400%2Fnginx%20(%22400%20Bad%20Request%20in%20nginx%22)%20in%205%20bullet%20points%2C%20then%20tell%20me%20the%20one%20thing%20I%20should%20do%20next.)

_01_What nginx logs at info level for a 400

## Why nginx returns a 400

RFC 9110 says a 400 means the server "cannot or will not process the request due to something that is perceived to be a client error". In nginx that covers malformed requests and a few size limits. The general meaning, and the checklist for visitors, are on [400 Bad Request](/errors/http/400). This page covers what is specific to nginx.

Log message

### `client sent too long header line`

Cause

A request header field is larger than one `large_client_header_buffers` buffer

Log message

### `client sent invalid header line`

Cause

A header line nginx cannot parse. With `ignore_invalid_headers on` (the default), a field with an invalid name is logged with this message but skipped, not rejected

Log message

### `client sent invalid host header`

Cause

The Host header failed nginx's host validation

Log message

### `client sent plain HTTP request to HTTPS port`

Cause

A client used `http://` against a port configured with `ssl`

The 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.

Log the reason for a 400 (temporary)

```
# Default is: error_log logs/error.log error; error_log /var/log/nginx/error.log info;
```

_02_nginx 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](/glossary/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](/glossary/entity) 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](/errors/http/431).

**Bigger buffers are a patch, not a cure**The nginx docs say buffers are allocated only on demand. Still, a cookie that keeps growing will outgrow any limit. Find which cookie grows, and expire it.

_03_Check 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](/seo-issues/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. 01 [RFC 9110: HTTP Semantics](https://www.rfc-editor.org/rfc/rfc9110.html) rfc-editor.org · checked 2026-10-25
2. 02 [nginx: ngx_http_core_module](https://nginx.org/en/docs/http/ngx_http_core_module.html) nginx.org · checked 2026-10-25
3. 03 [nginx: core functionality (error_log)](https://nginx.org/en/docs/ngx_core_module.html) nginx.org · checked 2026-10-25
4. 04 [nginx source: src/http/ngx_http_request.c](https://github.com/nginx/nginx/blob/master/src/http/ngx_http_request.c) github.com · checked 2026-10-25
5. 05 [nginx source: src/http/ngx_http_special_response.c](https://github.com/nginx/nginx/blob/master/src/http/ngx_http_special_response.c) github.com · checked 2026-10-25
6. 06 [RFC 6585: Additional HTTP Status Codes](https://www.rfc-editor.org/rfc/rfc6585.html) rfc-editor.org · checked 2026-10-25
7. 07 [How HTTP status codes affect Google's crawlers](https://developers.google.com/crawling/docs/troubleshooting/http-status-codes) developers.google.com · checked 2026-10-25

Questions

## Asked a lot.

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

_01_ How 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.

_02_ How 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.

_03_ What 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.

_04_ Why 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.

## Keep learning

[All errors](/errors)

[Learn 413 Request Entity Too Large in nginx HTTP status codes](/errors/http/413/nginx) [Related HTTP 431 Request Header Fields Too Large HTTP status codes](/errors/http/431) [Read next HTTP 400 Bad Request HTTP status codes](/errors/http/400) [Do Run a free site audit Free, about two minutes](/site-audit)

Other 400 errors
[400 Bad Request in Chrome](/errors/http/400/chrome) [400 Bad Request in Django](/errors/http/400/django) [400 Bad Request in Flask](/errors/http/400/flask) [400 Bad Request in Spring Boot](/errors/http/400/spring-boot) [CloudFront 400: Bad Request](/errors/cdn/cloudfront-400)

Nearby in errors
[HTTP 401 Unauthorized](/errors/http/401)

More in HTTP 400 Bad Request
[400 Bad Request in Apache httpd](/errors/http/400/apache) [400 Bad Request in Chrome](/errors/http/400/chrome) [400 Bad Request in Django](/errors/http/400/django) [400 Bad Request in Flask](/errors/http/400/flask) [400 Bad Request in nginx](/errors/http/400/nginx) [400 Bad Request in Spring Boot](/errors/http/400/spring-boot)

Terms on this page
[HTTPS](/glossary/https) [Entity](/glossary/entity)

Free · 2 minutes

## Tools point. Agencies advise. _This one ships._

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

[Audit my site free](/site-audit)

Free, no card 60 seconds Nobody will call you

- **46** fixes shipped without a ticket Brightpipe
- **0→7** ChatGPT citations in six weeks Paylane
