When configuring Apache as a reverse proxy to localhost services, developers often encounter the frustrating "proxy: pass request body failed" error. This typically occurs when Apache cannot properly forward HTTP request bodies to the backend service.
The original configuration shows several potential issues:
<VirtualHost *:80>
ServerName xxxxx.domain.tdl
SSLProxyEngine On
SSLProxyCheckPeerCN on
ProxyPass / https://localhost:1234
ProxyPassReverse / https://localhost:1234
</VirtualHost>
The configuration needs these critical additions:
# Required modules must be loaded
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
# Timeout settings to prevent premature failures
ProxyTimeout 300
Timeout 300
# Keepalive settings
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
Here's a tested solution that resolves the body forwarding issue:
<VirtualHost *:80>
ServerName proxy.example.com
# Core proxy settings
ProxyRequests Off
ProxyPreserveHost On
ProxyVia On
# Timeout configurations
ProxyTimeout 300
Timeout 300
# SSL settings when proxying HTTPS
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off
# Proxy mappings with proper scheme handling
ProxyPass / http://localhost:1234/ connectiontimeout=300 timeout=300
ProxyPassReverse / http://localhost:1234/
# Request body handling directives
SetEnv proxy-nokeepalive 1
SetEnv force-proxy-request-1.0 1
</VirtualHost>
If the problem persists, check these aspects:
# Verify backend service is running
curl -v http://localhost:1234
# Check Apache error logs
tail -f /var/log/apache2/error.log
# Test request forwarding
curl -X POST -d "test=body" http://proxy.example.com
For complex cases, consider these additional measures:
- Verify SELinux/apparmor permissions
- Check for conflicting firewalls (iptables/ufw)
- Test with different request body sizes
- Inspect network connectivity between Apache and backend
html
When configuring reverse proxy with Apache's ProxyPass
, many developers encounter the frustrating "proxy: pass request body failed" error. Let's examine a typical scenario where this occurs:
<VirtualHost *:80>
ServerName xxxxx.domain.tdl
SSLProxyEngine On
SSLProxyCheckPeerCN on
ProxyPass / https://localhost:1234
ProxyPassReverse / https://localhost:1234
</VirtualHost>
The error message reveals multiple potential issues:
- Connection refused by backend server (localhost:1234)
- SSL/TLS handshake failure
- Request body size limitations
- IPv6 vs IPv4 addressing conflicts
First, verify the backend service is running:
curl -v http://localhost:1234
netstat -tulnp | grep 1234
Here's a proven setup that handles request bodies properly:
<VirtualHost *:80>
ServerName api.example.com
# Timeout and buffer settings
ProxyTimeout 300
ProxyIOBufferSize 8192
# Important for request body handling
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
# SSL configuration
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
# Proxy settings
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:1234/ retry=5 timeout=30
ProxyPassReverse / http://localhost:1234/
# Logging
ErrorLog ${APACHE_LOG_DIR}/api_error.log
CustomLog ${APACHE_LOG_DIR}/api_access.log combined
</VirtualHost>
These parameters are critical for proper request body handling:
# Adjust based on your expected payload size
LimitRequestBody 1073741824
# For large file uploads
ProxyReceiveBufferSize 16384
If using HTTPS backend, add these diagnostic steps:
openssl s_client -connect localhost:1234 -showcerts
apachectl -t -D DUMP_VHOSTS
For Node.js/Python backends, consider adding these headers:
# Nginx equivalent for comparison
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Remember to test configuration changes with apachectl configtest
before restarting.