mod_proxy on Apache 2.2.3 proxying to Tomcat 5.5 returns Error 502 Bad Gateway

5,250

Update

Have you tried monitoring the number of busy threads in Tomcat? Perhaps Apache is not releasing them properly.


First attempt, not working

Reverse name lookups for DOMAIN?

I'm going to shamelessly plug my stack overflow answer. Note that it allows you to use localhost instead of DOMAIN.

<VirtualHost *:80>
  ServerName public.server.name

  ProxyRequests Off
  ProxyPreserveHost On

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  ProxyPass / http://localhost:8180/
  ProxyPassReverse / http://localhost:8180/
</VirtualHost>
Share:
5,250

Related videos on Youtube

Karolis T.
Author by

Karolis T.

Live long and prosper.

Updated on September 17, 2022

Comments

  • Karolis T.
    Karolis T. over 1 year

    I'm getting a 502 bad gateway error when using mod_proxy on Apache 2.2.3 proxying to Tomcat 5.5.

    It works correctly when used directly via Tomcat (not via mod_proxy), so I assume the problem is on Apache's end. The problem arises when request takes longer than normal, but I'm yet to see any pattern. Sometimes two seconds are too long, sometimes seven.

    Tomcat is used to host a Groovy/Grails based application.

    Apache vhost config has these relevant entries:

    ProxyRequests Off
    ProxyTimeout 1800
    
    <Proxy *>
     Order deny,allow
     Allow from all
    </Proxy>
    <Location />
    ProxyPass http://DOMAIN:8180/
    ProxyPassReverse http://DOMAIN:8180/
    SetEnv force-proxy-request-1.0 1
    SetEnv proxy-nokeepalive 1
    </Location>
    UseCanonicalName off
    HostNameLookups off
    

    Please note that I've added ProxyTimeout in an attempt to solve the problem (have helped in similar situations in the past), it didn't help.

    These two lines are old, without them the situation is worse - error 502 on almost every request.

    SetEnv force-proxy-request-1.0 1
    SetEnv proxy-nokeepalive 1
    
  • Karolis T.
    Karolis T. almost 15 years
    The issue still exists, I don't think it's related to name lookups.
  • Karolis T.
    Karolis T. almost 15 years
    Regarding your update: apache and tomcat are not integrated, they talk to each other via mod_proxy. Does apache have to release tomcat threads in this situation? How to monitor their number? ThanksĄ
  • Robert Munteanu
    Robert Munteanu almost 15 years
    I'm not sure when/if Apache releases the Tomcat threads - we're talking HTTP connections here. You can monitor thread usage using the manager html application $TOMCAT/manager/html .
  • Karolis T.
    Karolis T. almost 15 years
    Thanks, I was able to solve it, removing the possibility of too much busy threads via tomcat manager app.