I don’t know if you have come across the all but wonderful Apache HTTP “502 Proxy Error”, but if you have you know it is a pain to diagnose. I just ran across this problem the other week. After much research, I found out that there are all kinds of little things that can cause this to happen. Everything from a application taking to long to respond to firewall and load balancer issues.
In my case we had a lot of things to look at. We were front ending a Glassfish cluster with a Apache HTTP server doing a proxy passthrough connection. The traffic between the HTTP server and the Glassfish cluster is being handled by a load balancer and passing through a firewall. What I discovered was that Glassfish would close a connection from the Proxy Server but the Proxy Server would see the connections as still being open. The next request would try to aquire, what it thought was a open connection, and would fail with this error.
To fix this issue I added the disablereuse and retry attributes to the ProxyPass connection. Here is a example of them being used. You need to set disableresue to On and retry to 0.
ProxyPass /example http://backend.example.com disableresue=On retry=0
I set retry to 0 so that that there is no wait in retrying a request. According to the Apache HTTP Documentation the disableresue should only be used in rare occasions where the connection is randomly dropped.
copied from the apache documentationThis parameter should be used when you want to force mod_proxy to immediately close a connection to the backend after being used, and thus, disable its persistent connection and pool for that backend. This helps in various situations where a firewall between Apache and the backend server (regardless of protocol) tends to silently drop connections or when backends themselves may be under round- robin DNS. To disable connection pooling reuse, set this property value to On.
Now that I have added these attributes I have not gotten the 502 Proxy Error once.