Apache2 + Tomcat:通过apache2接收请求会导致超时和代理错误

所以我们使用apache作为反向代理来发送请求到我们的solr(search应用程序),它是在tomcat中托pipe的。

我们有另外一台服务器托pipe在jboss中,它以二进制格式向apache发送数据,然后将这些数据发送给tomcat进行索引并放入solr数据库。 数据以多部分POST请求发送。 这个过程可能需要长达8个小时。

所以这里的问题是,当我们通过apache发送数据时,在索引(发送数据部分)中间大约30-40分钟,我们会在jboss(发送数据部分)中收到很多代理和错误的网关错误数据),并在tomcat日志中,它会说,收到的数据有一个无效的EOF。 所以显然数据没有正确发送。 如果我们看一下apache日志,这个错误有很多:

[Wed Jan 08 16:10:45 2014] [error] [client 10.60.6.6] (70007)The timeout specified has expired: proxy: error reading status line from remote server localhost:8080 [Wed Jan 08 16:10:45 2014] [error] [client 10.60.6.6] proxy: Error reading from remote server returned by /application-path/application-url 

和这个错误:

 [Mon Jan 13 11:38:49 2014] [error] (103)Software caused connection abort: proxy: pass request body failed to [::1]:8080 (localhost) [Mon Jan 13 11:38:49 2014] [error] proxy: pass request body failed to [::1]:8080 (localhost) from 10.3.40.76 () 

奇怪的是,如果我们绕过apache(:80)并直接发送数据到tomcat(:8080),我们从来没有遇到过这个问题。 起初,这个问题看起来可能与此相同。

但是tomcat和apache没有保持活动状态。

 Timeout 120 KeepAlive Off <VirtualHost *:80> ServerName application.com ServerAlias x.application.com DocumentRoot /var/www/something/ ServerAdmin [email protected] # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" \"%{soapAction}i\"" logging CustomLog /log/httpd/access.log logging ErrorLog /log/httpd/error.log ServerSignature On RewriteEngine On RewriteLogLevel 2 # ensure that Tomcat sees the original host and port (and not the proxy-host and -port) ProxyPreserveHost On # Rewrite Rules RewriteRule ^/application-path/(.*) http://localhost:8080/application-path/$1 [P] </VirtualHost> 

和在tomcat中

 <Connector connectionTimeout="10000" port="8080" protocol="HTTP/1.1" redirectPort="8443" maxThreads="1000" processorCache="1000" maxKeepAliveRequests="1" keepAliveTimeout="10" socket.soReuseAddress="true" socket.soKeepAlive="true" compression="on" compressionMinSize="10" compressableMimeType="text/html,text/xml,text/plain,application/javascript,application/json,text/javascript,text/css" socket.soLingerOn="false" socket.soLingerTime="0" URIEncoding="UTF-8" /> 

对于那些想知道的,是的,Apache比tomcat有更大的超时,并且都closures了keep-alive,所以当tomcat没有时,为什么apache会返回超时。

我们遇到类似的问题,我们绕过了Apache完全通过使用iptables转发所有通信从端口80到8080.不知道这是否适用于你。

你也可以让tomcat监听端口80.(不知道你有没有其他的网站在80上监听。)