Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Servers, nginx and Docker · Troubleshooting walkthrough

Apache logs AH01084: pass request body failed to the backend

Short answer

"AH01084: pass request body failed to 127.0.0.1:8080" means Apache httpd 2.4 could not write the proxied request, headers included, to the backend. The status it returns names the cause: 500 with Error during SSL Handshake is a failed TLS handshake, 502 is a backend that closed the connection, and 504 is a backend that stopped reading.

  • Applies to Apache httpd 2.4.71, mod_proxy_http and mod_ssl, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

AH01084: pass request body failed to <host:port> is Apache httpd 2.4 reporting that it could not write the proxied request, headers included, to the backend. The line itself does not say why. The status code the client received afterwards does.

A 500 that comes with AH00898: Error during SSL Handshake points at TLS between Apache and an https backend. A 502 means the backend closed the connection. A 504 means the backend stopped reading until the proxy timeout ran out.

The text you see

  • AH01084: pass request body failed to 127.0.0.1:8443 (localhost)
  • AH00898: Error during SSL Handshake with remote server returned by /api/upload

Stage 1

Pair each log line with its status

First collect the AH01084 lines with the line after each, then the statuses Apache sent for the same period. Match them by time. One error log can mix all three causes, so do not assume the first status you see is the only one.

Error lines and the statuses that go with them

sudo grep -n -A1 "AH01084" /var/log/apache2/error.log | tail -n 20
sudo awk '$9 ~ /^50[024]$/ {print $4, $7, $9}' /var/log/apache2/access.log | tail -n 20
What follows AH01084StatusMeaning
AH00898: Error during SSL Handshake500TLS to the backend failed
Nothing else, sporadic, mostly POST or PUT502Backend closed a reused connection
Nothing else, large uploads or load504Backend accepted but stopped reading

Stage 2

500 with a handshake error: the https backend

Apache opened the TCP connection to an https:// backend, and mod_ssl refused the TLS session on the first write. mod_ssl logs the reason at info level only, so raise the level for the SSL module for a moment. Look for SSL Proxy connect failed, Peer certificate is expired, or Peer certificate does not match for hostname. The last appears because SSLProxyCheckPeerName is on by default and compares the host in ProxyPass with the certificate.

Make mod_ssl say why

# in the virtual host, temporarily
LogLevel warn ssl:info
sudo systemctl reload apache2
sudo grep -E "AH02003|AH02004|AH02411" /var/log/apache2/error.log | tail -n 5

The fix

Use in ProxyPass the host name the backend certificate was issued for, give mod_ssl the CA that signed it, and renew the certificate if it has expired. For an app on the same machine, plain http on the loopback address avoids the second TLS hop entirely.

SSLProxyEngine on
SSLProxyVerify require
SSLProxyCACertificateFile "/etc/ssl/certs/internal-ca.pem"
ProxyPass        "/api/" "https://api.internal.example.com:8443/api/"
ProxyPassReverse "/api/" "https://api.internal.example.com:8443/api/"

Stage 3

502 now and then: a kept-alive connection that died

Apache keeps connections to the backend in a pool and reuses them. If the backend's own keep-alive timeout closes a connection at the moment Apache writes to it, the write fails and the client sees a 502. The mod_proxy_http docs describe this race, and mod_proxy offers the ttl parameter for it.

The pattern is characteristic: it hits requests with bodies, and the first request after a quiet period, while the backend looks healthy.

Retire pooled connections before the backend does

# backend keeps idle connections for 5 s, so retire them sooner
ProxyPass "/api/" "http://127.0.0.1:8080/api/" ttl=4

# alternatives
SetEnv proxy-initial-not-pooled 1
ProxyPass "/api/" "http://127.0.0.1:8080/api/" disablereuse=On

Set ttl below the backend's keep-alive timeout. disablereuse=On is the blunt option, because every request then opens a new connection.

Stage 4

504 on large uploads: the backend stopped reading

The backend accepted the connection but stopped taking data, so Apache's buffer towards it stayed full until the timeout. The socket timeout is the timeout parameter of ProxyPass, or ProxyTimeout when that is unset.

First find why the backend stalls: a full worker pool or a blocked disk are common. If the uploads are simply large and slow, raise the timeout for that route only, so a hung backend elsewhere still fails fast.

Find existing timeouts, then raise one route

sudo grep -rn "ProxyTimeout\|timeout=" /etc/apache2/
ProxyPass "/upload/" "http://127.0.0.1:8080/upload/" timeout=300

Stage 5

Reload Apache and replay the failing POSTs

Check the syntax, reload, and repeat the request that failed. For the 502 case, run a burst of POSTs spaced just longer than the backend keep-alive and count the statuses.

Reload and probe

sudo apachectl configtest && sudo systemctl reload apache2
for i in $(seq 1 10); do curl -s -o /dev/null -w "%{http_code}\n" -X POST -d 'x=1' https://example.com/api/ping; sleep 6; done | sort | uniq -c

Stage 6

When none of the three fits

If the status is something else, or AH01084 appears on WebSocket routes (ProxyPass with upgrade=websocket), capture the backend side of the connection. The process may be crashing or resetting sockets under load.

If you only keep one thing

  • AH01084 is a symptom; the status code names the cause.
  • 500 plus AH00898 is TLS, 502 is a closed pooled connection, 504 is a stalled backend.
  • Set ttl below the backend keep-alive and keep LogLevel ssl:info one reload away.

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.