The browser shows a page like this, with HTTP status 502 Bad Gateway:
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request
Reason: Error reading from remote server
Apache is acting as a reverse proxy with mod_proxy, and it connected to your backend (Tomcat, Node.js, Gunicorn, PHP-FPM over HTTP, another web server) but the reply was missing, cut short or unreadable. The page is generated by Apache, so the problem is between Apache and the application behind it, not in the visitor's browser. See Fix 502 Bad Gateway for the general version.
Look at Apache's error log for the line that goes with it:
AH01102: error reading status line from remote server 127.0.0.1:8080
AH00898: Error reading from remote server returned by /api/report
(70007)The timeout specified has expired: AH01102: error reading status line from remote server
(104)Connection reset by peer: AH01102: error reading status line from remote server
The text after the colon tells you which of the causes below you have. Error code details come from the operating system: 104 is a reset, 70007 is an APR timeout.
Cause 1: the backend crashed or restarted
If the backend process died while handling the request, or was restarted during a deploy, Apache sees the connection close without a response. Check the application's own log and process status:
systemctl status myapp
journalctl -u myapp --since "10 minutes ago"
dmesg | grep -i -E 'killed process|out of memory'
An out-of-memory kill is a frequent hidden cause. Fix the crash first; Apache is only the messenger.
Cause 2: timeout mismatch
The backend takes longer than Apache will wait. mod_proxy uses ProxyTimeout, which defaults to the global Timeout value (60 seconds in the stock 2.4 config):
ProxyPass /api/ http://127.0.0.1:8080/api/ timeout=120
ProxyPassReverse /api/ http://127.0.0.1:8080/api/
The timeout parameter on ProxyPass applies to that backend only. Do not raise it blindly. If a request legitimately needs minutes, move it to a background job. Also check any timeout in the app server (Gunicorn --timeout, for example), which may kill the worker first. For the timeout flavor, see Fix 504 Gateway Timeout and the nginx equivalent in nginx upstream timed out.
Cause 3: stale keepalive connections
Apache reuses backend connections. If the backend closes idle connections sooner than Apache expects, Apache writes a request onto a connection that is already dead and gets "error reading status line". It shows up as occasional 502s that retry successfully, mostly after idle periods. Two fixes:
# Option A: do not reuse backend connections
ProxyPass / http://127.0.0.1:8080/ disablereuse=On
# Option B: expire pooled connections before the backend does (seconds)
ProxyPass / http://127.0.0.1:8080/ ttl=30
Alternatively raise the backend's keepalive timeout above Apache's. disablereuse=On is the simplest test; if the 502s vanish, you have confirmed the cause, and ttl is the cheaper long-term choice.
Cause 4: wrong protocol or port
Proxying http:// to a port that speaks HTTPS (or the reverse) produces garbage responses. Verify with curl from the Apache host:
curl -v http://127.0.0.1:8080/
curl -vk https://127.0.0.1:8443/
For HTTPS backends you need SSLProxyEngine On plus the https:// scheme. Confirm the port is listening using the पोर्ट चेकर from outside, and ss -ltnp locally. If nothing listens, Apache logs "Connection refused" (AH00957) and the status is 503 or 502; see nginx connect() failed (111) for the equivalent diagnosis.
Cause 5: malformed response or a device in the middle
An app that sends invalid headers or a duplicate Content-Length can make mod_proxy abort; capture the raw reply with curl -i and look for oddities. A WAF, mod_security or network device that resets large requests causes intermittent resets. Test the same request directly against the backend: if it succeeds there, the fault is in the proxy path.
Triage order
- Open the Apache error log and read the exact AH code and OS error.
- Request the backend directly with
curl. Does it respond, and how long does it take? - Check the backend process log for crashes and slow requests.
- If errors are sporadic, try
disablereuse=On. - If errors correlate with long requests, adjust
timeoutand the app server timeout together.
How to verify
Repeat the failing request several times with curl -s -o /dev/null -w '%{http_code} %{time_total}\n' and confirm consistent 200s. Use the HTTP स्टेटस चेकर to see what the public URL returns, the वेबसाइट स्पीड टेस्ट to check response time, and the Outage Root Cause Finder if the cause is still unclear. An अपटाइम मॉनिटर catches intermittent 502s that manual testing misses.
अगले कदम
- Read Fix 502 Bad Gateway.
- Tune timeouts with nginx 502 and 504 timeout tuning if nginx sits in front.
- Check Apache capacity in MaxRequestWorkers reached.
- Review the HTTP 502 reference.
सामान्य प्रश्न
Is this the same as a 504?
No. A 504 means the proxy gave up waiting; this error means the connection ended or the response was unreadable. Timeouts can log as either, depending on where they hit.
Why do some requests fail and an immediate retry works?
That pattern points to stale pooled connections. Set disablereuse=On or a ttl, or lengthen the backend keepalive.
Does ProxyTimeout fix it?
Only if the cause is a slow backend. If the backend crashed or reset the connection, a longer timeout changes nothing.
Can the problem be on the client side?
Rarely. The page is created by Apache after talking to the backend, so inspect the proxy and backend first.
Get notified when this fix updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.