502 Bad Gateway... 来自上游服务器(apache 和 jboss)的无效响应
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1109241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
502 Bad Gateway... invalid response from upstream server (apache and jboss)
提问by ravun
I'm using apache on one machine to serve requests to jboss on another machine. Everything works fine when I startup jboss and I'm able to access the web app, but after a few hours I eventually start getting "The proxy server received an invalid response from an upstream server" errors. If I restart jboss then everything works fine again, but several hours later I have the same issue...
我在一台机器上使用 apache 来为另一台机器上的 jboss 提供请求。当我启动 jboss 并且我能够访问 Web 应用程序时一切正常,但几个小时后我最终开始收到“代理服务器收到来自上游服务器的无效响应”错误。如果我重新启动 jboss 然后一切正常,但是几个小时后我遇到了同样的问题......
Does anybody know what could be causing this issue? I don't have access to the apache logs at this time (I should in a few hours) but it seems to be something with jboss since restarting it is the temporary fix.
有谁知道是什么导致了这个问题?我目前无法访问 apache 日志(我应该在几个小时内访问)但它似乎与 jboss 有关,因为重新启动它是临时修复。
I'm using jboss4.2.3 and apache 1.3 with mod_jk. I'm not finding any errors in the jboss logs and the app I'm trying to reach isn't doing anything that takes a long time. The main page is just a simple login page. I have ports 8009 and 8080 open for communication between the app server and web server. I don't know what configuration is wrong.
我正在使用带有 mod_jk 的 jboss4.2.3 和 apache 1.3。我没有在 jboss 日志中发现任何错误,而且我试图访问的应用程序没有做任何需要很长时间的事情。主页只是一个简单的登录页面。我打开了端口 8009 和 8080,用于应用服务器和 Web 服务器之间的通信。不知道是什么配置不对。
回答by skaffman
This sounds to me like mod_jk in Apache is getting out of sync with the AJP connector in JBoss. The AJP protocol uses persistent, re-used connections between web server and app server, and if the protocol is not configured exactly the same on both ends of the connection, eventually the connections go stale at one end of the connection, but the other end keeps trying to use them. The symptom is a 502 error.
这听起来像是 Apache 中的 mod_jk 与 JBoss 中的 AJP 连接器不同步。AJP 协议在 Web 服务器和应用程序服务器之间使用持久的、重复使用的连接,如果该协议在连接两端的配置不完全相同,最终连接在连接的一端会失效,但在另一端一直在尝试使用它们。症状是 502 错误。
My first suggestion is this: don't use mod_jk unless you need to. It's complex and hard to configure to get a stable system. If you don't need its performance or load balancing features, I suggest using mod_proxy instead. It's just as good for most applications, and pretty easy.
我的第一个建议是:除非需要,否则不要使用 mod_jk。要获得稳定的系统,配置起来既复杂又困难。如果您不需要它的性能或负载平衡功能,我建议改用 mod_proxy。它对大多数应用程序都一样好,而且非常简单。
But if you want to stick to mod_jk, The first thing you need to is make sure you're using the very latest mod_jk version (currently 1.2.28), since older versions are notoriously hard to configure. Luckily, mod_jk is still supported on Apache 1.3.
但是如果你想坚持使用 mod_jk,你需要做的第一件事就是确保你使用的是最新的 mod_jk 版本(当前是 1.2.28),因为众所周知,旧版本很难配置。幸运的是,Apache 1.3 仍然支持 mod_jk。
Next, check the mod_jk log file (configured using the JkLogFile directive). If you're seeing a bunch of connection-related errors around the time things go wrong, you need to tweak your jk config at both ends of the connection. The most likely culprit is the timeout settings, so read up about those here, and make sure both ends are singing from the same hymn sheet.
接下来,检查 mod_jk 日志文件(使用 JkLogFile 指令配置)。如果您在出现问题时看到一堆与连接相关的错误,则需要在连接的两端调整 jk 配置。最有可能的罪魁祸首是超时设置,因此请阅读此处的内容,并确保两端都在同一张赞美诗表中唱歌。
回答by dave
I've also seen this occur using apache and tomcat. In my particular situation, the application deployed to tomcat had a bug that caused response threads to hang. Eventually tomcat ran out of worker threads, and apache wasn't able to establish a connection.
我也看到使用 apache 和 tomcat 会发生这种情况。在我的特殊情况下,部署到 tomcat 的应用程序有一个错误,导致响应线程挂起。最终 tomcat 用完了工作线程,并且 apache 无法建立连接。
In our case, database connections weren't getting released properly back into a connection pool, and other threads were waiting indefinitely to obtain a connection from the pool. However, anything that indefinitely keeps alive a response handling thread could lead to the same problem.
在我们的例子中,数据库连接没有被正确释放回连接池,其他线程无限期地等待从池中获取连接。但是,任何使响应处理线程无限期保持活动状态的事物都可能导致相同的问题。
回答by andrade
I had the same issue but with Apache and Glassfish. Finally, I could fix it configuring the same timeout in both sides.
我有同样的问题,但 Apache 和 Glassfish。最后,我可以修复它在双方配置相同的超时。
In Glassfish changing the listener configuration and in Apache modifiying the worker.properties with this line:
在 Glassfish 中更改侦听器配置并在 Apache 中使用以下行修改 worker.properties:
worker.worker_name.socket_timeout=300
worker.worker_name.socket_timeout=300
I am not sure about the way to configure this in JBoss, may be modifying the web.xmlor cluster-service.xml.
我不确定在 JBoss 中配置它的方法,可能正在修改web.xml或cluster-service.xml.
回答by Suresh Ganta
If you are connecting Apachewith Tomcatand ended up in this blog just like me, it makes sense.
如果您将Apache与Tomcat连接起来并像我一样最终出现在这个博客中,那是有道理的。
Accepting connection for AJP/1.3 in tomcat solved this error for me. Do not forget to comment out the service on HTTP protocol.
在 tomcat 中接受 AJP/1.3 的连接为我解决了这个错误。不要忘记在 HTTP 协议上注释掉该服务。
**<!--<Connector port="8081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<Connector port="8081" protocol="AJP/1.3"
connectionTimeout="20000"
redirectPort="8443" />**

