Apache HTTP 502 Proxy Error

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 documentation

This 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.

Posted on Mar 18, 2009 by Mike Jennings in Web | 3 Comments | Permalink



Comments:

There is a typo in: disableresue
it should read: disablereuse

Posted by dave on June 08, 2009 at 04:36 PM EDT #

I am facing same issue. backend am using iis server. I tryied setting this attribute to proxypass and also tryied SetEnv fix. Both didnt fix this issue. I am getting this error when time taken to respond is too large, say more than 120 sec or the content that I am uploading or downloadin is big enoug.
Please guide me in resolving this issue.Stuck up for more than 2 weeks.

Posted by Kirant400 on August 11, 2009 at 03:18 PM EDT #

You might want to add a timeout setting to the end of your ProxyPass. You can read more about it here at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass

Posted by Mike Jennings on August 13, 2009 at 12:30 AM EDT #

Post a Comment:
Comments are closed for this entry.