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

What 400 Bad Request Means

A 400 status code means the server read the request and refuses it because something in it is malformed: the address, a header, a cookie, or the body. It is a client error, like 403 and 404, so compare the failing request with one that works. For the whole family of codes, see HTTP status codes.

What a Visitor Can Try

  • Check the address: a stray percent sign, a space, or a half-copied link can make it invalid.
  • Remove the cookies for that one site: a damaged or oversized cookie fails on every request. Deleting the site's cookies in the browser settings fixes it and logs you out of that site.
  • Try a private window: it starts without cookies and usually without extensions. If the page works there, one of the two caused the error.

If the error stays in a private window and on another network, the cause is on the server.

Oversized or Corrupt Cookies

This is the most common cause on a site that otherwise works. Nginx shows "400 Bad Request" with the line "Request Header Or Cookie Too Large" when a header line does not fit its buffers, set by the large_client_header_buffers directive (four buffers of 8 KB by default). Apache has a similar per-line limit of about 8 KB, set by LimitRequestFieldSize.

The lasting fix is in the application: store less in cookies and keep session data on the server. Raising the limit is reasonable for headers that are legitimately large; the config lines are in 431 Request Header Fields Too Large.

Plain HTTP Sent to an HTTPS Port

Nginx answers "400 Bad Request" with the line "The plain HTTP request was sent to HTTPS port" when a client speaks plain HTTP to a TLS port, for example through an address such as http://example.com:443 or a proxy that forwards plain HTTP to port 443. Reproduce it:

curl -i http://example.com:443/

Correct the link or the proxy so it uses https. Nginx gives this case the internal code 497, which you can turn into a redirect in the server block that listens on 443:

error_page 497 =301 https://$host$request_uri;

A Missing or Invalid Host Header

HTTP/1.1 requires a Host header, and servers reject a request without one or with a value a host name cannot contain. Browsers always send a valid one, so this comes from scripts and monitoring tools. Test it on your own server:

curl -i --http1.1 -H "Host:" http://203.0.113.10/

Some configurations also return 400 on purpose from a default server block for unknown names. If a real domain lands there, its server_name line is missing or misspelled; see Nginx server blocks.

Malformed Addresses and Request Bodies

  • Invalid characters: a percent sign not followed by two hex digits, or a raw space, can be rejected before the application sees the request. Encode them, for example a space as %20.
  • Bodies the application cannot parse: an API returns 400 itself for invalid JSON or a missing field, and the response body usually names it.
  • Size limits: a body over the limit normally gives 413; see 413 Request Entity Too Large.

Find the Cause in the Logs

In the default combined log format, the status code follows the quoted request line. A malformed request line can contain extra spaces, so search for the quote and the code together instead of counting fields:

sudo grep '" 400 ' /var/log/nginx/access.log | tail -20

For Apache, read /var/log/apache2/access.log on Ubuntu and Debian or /var/log/httpd/access_log on AlmaLinux and Rocky Linux. Nginx writes the reason for a rejected request to its error log only at the info level, which is not on by default. Set it for a short time, reload, and reproduce the error:

error_log /var/log/nginx/error.log info;
sudo nginx -t && sudo systemctl reload nginx
sudo tail -f /var/log/nginx/error.log

A line saying the client sent an invalid request, an invalid host header, or a too long header line names the cause. Apache also logs many of these reasons below its default warn level; raise LogLevel to info, or debug for some messages, for a short time in the same way. See Nginx logs and Apache logs.

Confirm the Fix

curl -sI https://example.com/ | head -1

Then load the page in a normal browser window that still has its old cookies. Set the Nginx error log level back to its previous value and reload.

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