Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Servers, nginx and Docker · Decision guide

Apache answers 400 Bad Request: your browser sent a request it could not understand

Short answer

Apache 2.4 shows Your browser sent a request that this server could not understand, with status 400, when it rejects a request before any site code runs. The Reason line or the error log names the case: plain HTTP sent to an SSL port, a header longer than LimitRequestFieldSize (8190 bytes by default), or a request that breaks HttpProtocolOptions Strict.

  • Applies to Apache httpd 2.4.58, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

A 400 from Apache with the sentence "Your browser sent a request that this server could not understand" comes from the server's own front door. The request was refused before PHP, a proxy target or any site code saw it. Apache usually knows why and says so, in a Reason line under the sentence, in the error log, or both.

Three situations produce nearly all of these on Apache 2.4. Which one you have depends on how the request got there, so start from the evidence you can see and jump to the matching section.

Find your case

  1. If The page says you are speaking plain HTTP to an SSL-enabled server portAn http:// request reached a port that expects TLS.
  2. If The page or log says the size of a request header field exceeds the server limitA header, usually Cookie, is bigger than LimitRequestFieldSize.
  3. If No reason line, only one script, device or old client failsThat client's request breaks the strict grammar Apache enforces.
  4. If The error page does not look like Apache's at allA proxy, firewall or CDN in front produced it.

First, read the reason

Repeat the failing request with curl so you see the response body without browser caching, and look at the newest error log lines for the same moment. Apache adds a second line to the page when it knows the cause.

Debian and Ubuntu paths; other systems log elsewhere

curl -s -i https://example.com/failing/path | head -n 20
sudo tail -n 20 /var/log/apache2/error.log

Plain HTTP on the SSL port

mod_ssl notices that a connection on an SSLEngine on port did not start with a TLS handshake and answers with the note about speaking plain HTTP. The usual senders are a hand-typed http://example.com:443/, and a load balancer or reverse proxy that forwards plain HTTP to port 443 of the back end.

Make the sender use the right scheme: https for the TLS port, or plain HTTP to port 80. For visitors who arrive on port 80, a virtual host there that only redirects is the clean answer.

Port 80 host that redirects to HTTPS

<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / https://example.com/
</VirtualHost>

Test the config with sudo apachectl configtest before sudo systemctl reload apache2.

An oversized header

LimitRequestFieldSize caps the length of a single request header at 8190 bytes by default. Signed-in users with many or large cookies cross it first, which is why the error often hits only logged-in visitors. The core module logs the offending header name as AH00561 once its log level is raised to info.

Shrink the header before raising the limit: fewer cookies, smaller tokens, session data on the server. Apache's manual advises keeping the default under normal conditions. If you do raise it, set it in the main server configuration, since with name-based virtual hosts the value is taken from the first virtual host for that address and port.

Find which header it is

# for the diagnosis only
LogLevel warn core:info
# then
sudo grep AH00561 /var/log/apache2/error.log | tail -n 5

A client that breaks the request grammar

Since 2.4.24 the default HttpProtocolOptions Strict makes Apache check each request against the HTTP grammar in RFC 7230 before processing it. Browsers comply; hand-written scripts, embedded devices and old libraries sometimes do not, for example an unencoded space in a URL or a header name containing a space.

At core:debug the error log names the problem, such as AH02426 for a malformed header field name or AH03454 for an incorrectly encoded URI. Fix the client: percent-encode the URL, send valid header names. Apache's manual strongly warns against Unsafe on public servers; if an internal tool truly cannot change, confine Unsafe to a virtual host reachable only on a private address.

Temporary debug logging and the lines to look for

LogLevel warn core:debug
sudo grep -E "AH02426|AH03454|AH03447" /var/log/apache2/error.log | tail -n 5

Put LogLevel back to warn afterwards; debug logs grow quickly.

When it is not Apache

If the 400 page does not use Apache's wording and none of the log lines above appear even at debug level, the response came from something in front of httpd: a CDN, WAF, load balancer or another proxy. Check that layer's logs and its own header size limits.

In short

  • The Reason line or the error log names the case; read them before changing anything.
  • Keep a port 80 host that only redirects to HTTPS.
  • Cut cookie size before raising LimitRequestFieldSize.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want a second pair of eyes on it?

Send me the error and what changed before it started. I reply within 24 hours.