tomcat 的 apache 代理保持活跃混乱
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1787557/
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
apache proxy to tomcat keep alive confusion
提问by Patrick
I have an apache 2.2 server infront of a tomcat 6 server. using mod_proxy_ajp on apache to proxy requests to tomcat. pretty standard setup.
我在 tomcat 6 服务器前面有一个 apache 2.2 服务器。在 apache 上使用 mod_proxy_ajp 将请求代理到 tomcat。非常标准的设置。
If I need to disable keep-alive connections for browsers, how do i do this?
如果我需要禁用浏览器的保持活动连接,我该怎么做?
I need to do disable keep-alive http requests because i suspect some of my users have firewalls that might be dropping an un-active keep-alive connection which randomly causes problems.
我需要禁用保持活动的 http 请求,因为我怀疑我的一些用户的防火墙可能会丢弃一个不活动的保持活动连接,这会随机导致问题。
There are various 'keep alive' bits and pieces of configuration on both apache and tomcat.
在 apache 和 tomcat 上都有各种“保持活动”的零碎配置。
httpd.conf has "KeepAlive Off" (which does not seem to be making a difference in my case)
httpd.conf 具有“KeepAlive Off”(在我的情况下似乎没有什么不同)
also in httpd.conf where you set ProxyPass, you can have a parameter "keepalive" but this is only supposed to help if there are proxies/firewalls between my apache and tomcat, which there isn't in my case and is not the problem.
同样在您设置 ProxyPass 的 httpd.conf 中,您可以有一个参数“keepalive”,但这仅在我的 apache 和 tomcat 之间存在代理/防火墙时才有帮助,在我的情况下没有代理/防火墙,这不是问题.
Tomcat itself, the http connector has "keepAliveTimeout" and "maxKeepAliveRequests" but this is only for http connectors.
Tomcat 本身,http 连接器具有“keepAliveTimeout”和“maxKeepAliveRequests”,但这仅适用于 http 连接器。
The tomcat ajp connector also has a "keepAliveTimeout", but this is for ajp requests coming from apache, not sure if this should/flows on to the real HTTP request from the browser to apache.
tomcat ajp 连接器也有一个“keepAliveTimeout”,但这是针对来自 apache 的 ajp 请求,不确定这是否应该/流向从浏览器到 apache 的真实 HTTP 请求。
To top it all there is also the HTTP1.0 vs HTTP1.1 differentiation.
最重要的是还有 HTTP1.0 与 HTTP1.1 的区别。
So it gets confusing.... can someone please explain?
所以它变得混乱......有人可以解释一下吗?
回答by habe
There are (at least) four “keep-alive”s.
有(至少)四个“保持活动”。
HTTP layer keep-alive between client browser and Apache. (Enables multiple client requests in a HTTP/TCP connection. “KeepAlive” directive to configure.)
TCP layer keep-alive between client browser and Apache. (To avoid connection to be closed by firewalls, send empty packet periodically (around 2 hours by default in Linux). I don't know how to configure in Apache.)
AJP layer keep-alive between Apache and Tomcat. (Enables multiple Apache request in a AJP/TCP connection. “max” and “smax” options for “ProxyPass” to configure.)
TCP layer keep-alive between Apache and Tomcat. (Same as 2, but for firewall between Apache and Tomcat. “keepalive” option for “ProxyPass” directive to configure.)
HTTP 层在客户端浏览器和 Apache 之间保持活动状态。(在 HTTP/TCP 连接中启用多个客户端请求。要配置的“KeepAlive”指令。)
TCP 层在客户端浏览器和 Apache 之间保持活动状态。(为了避免连接被防火墙关闭,定期发送空包(Linux默认2小时左右)。我不知道如何在Apache中配置。)
AJP 层在 Apache 和 Tomcat 之间保持活动状态。(在 AJP/TCP 连接中启用多个 Apache 请求。要配置“ProxyPass”的“max”和“smax”选项。)
Apache 和 Tomcat 之间的 TCP 层保持活动状态。(与 2 相同,但用于 Apache 和 Tomcat 之间的防火墙。要配置“ProxyPass”指令的“keepalive”选项。)
So, your configuration (“KeepAlive off”) might work correctly for firewalls within client and Apache. Use “%X” for “LogFormat” directive to check if keep-alive (of type 1 above) was disabled.
因此,您的配置(“KeepAlive off”)可能适用于客户端和 Apache 中的防火墙。使用“%X”作为“LogFormat”指令来检查是否禁用了保持活动(上面的类型 1)。
By the way, I think connection closure by firewalls doesn't cause serious problem when “KeepAliveTimeout” is not so large. If you don't have problem (other than warning messages), in my opinion, you might leave as is.
顺便说一句,我认为当“KeepAliveTimeout”不是那么大时,防火墙关闭连接不会造成严重问题。如果您没有问题(警告消息除外),在我看来,您可以保持原样。

