
因此,我們使用 apache 作為反向代理將請求傳送到託管在 tomcat 中的 solr(搜尋應用程式)。
我們有另一台託管在 jboss 中的伺服器,它將二進位格式的資料傳送到 apache,apache 又將其傳送到 tomcat 進行索引並放入 solr 資料庫。資料作為多部分 POST 請求發送。此過程可能需要長達 8 小時。
那麼問題來了,當我們透過apache發送資料時,在索引中間(發送資料部分)大約30-40分鐘的時間裡,我們會在jboss(發送資料的部分)中收到很多proxy和bad gateway錯誤data ),並且在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沒有開啟keep-alive。
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>
在雄貓中
<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 的超時時間長,而且兩者都關閉了keep-alive,所以為什麼apache 會返回超時而tomcat 卻沒有返回超時,這是沒有意義的。
答案1
我們遇到了與您類似的問題,我們透過使用 iptables 將所有流量從連接埠 80 轉送到 8080 來完全繞過 Apache。
您也可以讓 tomcat 監聽 80 連接埠。