Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

up vote 1 down vote accepted

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|improve this answer
    
The issue still exists, I don't think it's related to name lookups. –  Karolis T. Jun 12 '09 at 8:24
    
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Ą –  Karolis T. Jun 15 '09 at 11:59
    
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 . –  Robert Munteanu Jun 15 '09 at 14:29
    
Thanks, I was able to solve it, removing the possibility of too much busy threads via tomcat manager app. –  Karolis T. Jun 16 '09 at 11:51

Although not a direct answer to your question, but we used to do Apache2<->Tomcat5 proxy in the following manner. Worked like a charm.

RewriteRule ^/$ http://apache.domain/appname/ [R]
RewriteRule ^/appname(.*)$ http://tomcat.domain:8081/appname$1 [P]
ProxyPassReverse /appname http://tomcat.domain:8081/appname
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.