502 Bad Gateway ... invalid response from upstream server (apache and jboss)

I am using apache on one computer to serve jboss requests on another machine. Everything works fine when I run jboss and I can access the web application, but after a few hours I will eventually start getting errors "The proxy received an incorrect response from the upstream server." If I restart jboss then everything will work fine, but after a few hours I will have the same problem ...

Does anyone know what might cause this problem? I don't have access to apache logs at this time (I should be in a few hours), but there seems to be something with jboss since the restart, this is a temporary fix.

I am using jboss4.2.3 and apache 1.3 with mod_jk. I find no errors in jboss logs and the application I am trying to achieve does nothing that takes a lot of time. The home page is just a simple login page. I have ports 8009 and 8080 open for communication between the application server and the web server. I do not know which configuration is wrong.

+4
source share
4 answers

It seems to me that mod_jk in Apache does not sync with the AJP connector in JBoss. The AJP protocol uses persistent, reusable connections between the web server and the application server, and if the protocol is not configured exactly at both ends of the connection, eventually the connections will become obsolete at one end of the connection and continue to try to use them at the other end. The symptom is error 502.

My first suggestion: do not use mod_jk unless you need to. It is difficult and difficult to configure in order to get a stable system. If you do not need performance or load balancing functions, I suggest using mod_proxy instead. This is just as good for most applications, and pretty easy.

But if you want to stick with mod_jk, the first thing you need to do is make sure you are using the latest version of mod_jk (currently 1.2.28), as older versions are generally difficult to configure. Fortunately, mod_jk is still supported on Apache 1.3.

Then check the mod_jk log file (configured using the JkLogFile directive). If you see a lot of connection-related errors while things go wrong, you need to configure your jk configuration at both ends of the connection. The most likely culprit is the timeout settings, so read about them here and make sure that both ends are sung from the same sheet of hymns.

+6
source

I also saw this using apache and tomcat. In my specific situation, an application deployed to tomcat had an error that caused response threads to hang. In the end, tomcat ended the worker threads and apache was unable to establish a connection.

In our case, connections to the database did not return properly to the connection pool, and other threads waited indefinitely to get a connection from the pool. However, anything that supports the response flow endlessly can lead to the same problem.

+2
source

I had the same issue, but with Apache and Glassfish. Finally, I could fix this by setting the same timeout on both sides.

In Glassfish, the listener settings are changed in Apache, changing the properties of worker.properties with this line:

worker.worker_name.socket_timeout=300

I'm not sure about how to configure this in JBoss, web.xml or cluster-service.xml can be changed.

0
source

If you connect Apache to Tomcat and get to this blog, just like me, this makes sense.

Accepting a connection for AJP / 1.3 in tomcat resolved this error for me. Remember to comment on the service over HTTP.

 **<!--<Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> --> <Connector port="8081" protocol="AJP/1.3" connectionTimeout="20000" redirectPort="8443" />** 
0
source

All Articles