Bad Gateway 502 error with Apache mod_proxy and Tomcat

前端 未结 10 1718
北海茫月
北海茫月 2020-12-12 16:24

We\'re running a web app on Tomcat 6 and Apache mod_proxy 2.2.3. Seeing a lot of 502 errors like this:

Bad Gateway! The proxy server received an in

10条回答
  •  Happy的楠姐
    2020-12-12 16:51

    If you want to handle your webapp's timeout with an apache load balancer, you first have to understand the different meaning of timeout. I try to condense the discussion I found here: http://apache-http-server.18135.x6.nabble.com/mod-proxy-When-does-a-backend-be-considered-as-failed-td5031316.html :

    It appears that mod_proxy considers a backend as failed only when the transport layer connection to that backend fails. Unless failonstatus/failontimeout is used. ...

    So, setting failontimeout is necessary for apache to consider a timeout of the webapp (e.g. served by tomcat) as a fail (and consecutively switch to the hot spare server). For the proper configuration, note the following misconfiguration:

    ProxyPass / balancer://localbalance/ failontimeout=on timeout=10 failonstatus=50

    This is a misconfiguration because:

    You are defining a balancer here, so the timeout parameter relates to the balancer (like the two others). However for a balancer, the timeout parameter is not a connection timeout (like the one used with BalancerMember), but the maximum time to wait for a free worker/member (e.g. when all the workers are busy or in error state, the default being to not wait).

    So, a proper configuration is done like this

    1. set timeout at the BalanceMember level:
     
         BalancerMember http://member1:8080/svc timeout=6 
     ... more BalanceMembers here
    
    
    1. set the failontimeout on the balancer
    ProxyPass /svc balancer://mycluster failontimeout=on
    

    Restart apache.

提交回复
热议问题