我们在mod_proxy_ajp中发生奇怪的间歇性错误,即使用apache作为tomcat服务器的前端 .
The error
-
用户点击链接浏览器会提示用户"save as...."(例如在Firefox中"You have chosen top open thread.jsp which is a application/octet-stream" ... firefox对此文件应该怎么做)
-
用户说"Huh?"并按"Cancel"
-
用户再次点击同一链接
-
浏览器正确显示页面
此错误间歇性地发生,但遗憾的是很少在我们的测试服务器上并且经常在 生产环境 中 .
在firefox的LiveHttpHeaders中,我在上面的用例中看到以下内容:
-
第一页下载(即点击链接)是"text/plain"
-
第二次下载是"text/html"
我认为问题可能源于ProxyPassReverse(即混淆了是否使用http或ajp),但所有这些proxypassreverse设置都导致了同样的错误:
-
ProxyPassReverse / ajp:// localhost:8080 /
-
ProxyPassReverse / pe http://localhost/pe
-
ProxyPassReverse / pe http://forumstest.company.com/pe
另外,我检查了apache错误日志(设置为debug),看不到警告或错误......
**但它适用于mod_proxy_http ?? **
似乎切换到mod_proxy_http'解决了这个问题 . 有限的测试,我无法在测试环境中重现问题 .
因为这个问题是间歇性的,所以我不能100%确定mod_proxy_http“解决”了这个问题
Environment
-
Apache 2.2 Windows
-
Jboss 4.2.2后端(tomcat 6)
One other data point
无论好坏,tomcat中的servlet过滤器会在将html发送到apache之前对其进行gzip压缩 . (这意味着额外的工作,因为apache必须在执行ProxyPassReverse的“查找和替换”之前解压缩) . 我不知道“gzip”是否会混乱 .
Questions
-
以前有人见过这个吗?
-
哪些工具有助于分析原因?
谢谢
Addendum 1: Here is the LiveHttpHeaders output
浏览器错误地将html视为"text/plain"
http://forums.customer.com/pe/action/forums/displaythread?rootPostID=10842016&channelID=1&portalPageId=1002
GET http://forums.customer.com/pe/action/forums/displaythread?rootPostID=10842016&channelID=1&portalPageId=1002 HTTP/1.1
Host: forums.customer.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Proxy-Connection: keep-alive
Cookie: __utma=156962862.829309431.1260304144.1297956514.1297958674.234; __utmz=156962862.1296760237.232.50.utmcsr=forumstest.customer.com|utmccn=(referral)|utmcmd=referral|utmcct=/pe/action/forums/displaythread; s_vi=[CS]v1|258F5B88051D3FC3-40000105C056085F[CE]; inqVital=xd|0^sesMgr|{"sID":4,"lsts":1292598007}^incMgr|{"id":"755563420055418864","group":"CHAT","ltt":1292598006741,"sid":"755563549194447187","igds":"1290627502757","exempt":false}^inq|{"customerID":"755562378269271622"}^saleMgr|{"state":"UNSOLD","qDat":{},"sDat":{}}; inqState=sLnd|1^Lnd|{"c":4,"flt":1274728016,"lldt":17869990,"pgs":{"201198":{"c":1,"flt":1274728016,"lldt":0},"0":{"c":3,"flt":1274845009,"lldt":17752997}},"pq":["0","0","0","201198"],"fsld":1274728016697}; adv_search_results_page=10; ep_beta=1; visitorID=57307059; JSESSIONID=6jXLNdHRDjR9Th3B5gvTVkw1dZLn1zvhvKLR2r4GTLjylHJgjY3Q!683274050; __utmc=156962862; JSESSIONID=6jXLNdHRDjR9Th3B5gvTVkw1dZLn1zvhvKLR2r4GTLjylHJgjY3Q!683274050; TLTHID=5CCA50304DE99E28DB79A7B3267D4231; TLTSID=9DFCDE8045B374AAB752CC98A30E8311; AreCookiesEnabled=1; s_cc=true; SC_LINKS=%5B%5BB%5D%5D; s_sq=%5B%5BB%5D%5D; __utmb=156962862.64.10.1297958674; memberexists=T; ev1=greywolf%20hdtv%20whmx
Cache-Control: max-age=0
HTTP/1.0 200 OK
Date: Thu, 17 Feb 2011 17:38:42 GMT
Content-Type: text/plain
X-Cache: MISS from samus.company.com
X-Cache-Lookup: MISS from samus.company.com:3128
Via: 1.0 samus.company.com:3128 (squid/2.6.STABLE20)
Proxy-Connection: close
----------------------------------------------------------
浏览器正确地将html视为"text/html"
http://forums.customer.com/pe/action/forums/displaythread?rootPostID=10842016&channelID=1&portalPageId=1002
GET http://forums.customer.com/pe/action/forums/displaythread?rootPostID=10842016&channelID=1&portalPageId=1002 HTTP/1.1
Host: forums.customer.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 ( .NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Proxy-Connection: keep-alive
Cookie: __utma=156962862.829309431.1260304144.1297956514.1297958674.234; __utmz=156962862.1296760237.232.50.utmcsr=forumstest.customer.com|utmccn=(referral)|utmcmd=referral|utmcct=/pe/action/forums/displaythread; s_vi=[CS]v1|258F5B88051D3FC3-40000105C056085F[CE]; inqVital=xd|0^sesMgr|{"sID":4,"lsts":1292598007}^incMgr|{"id":"755563420055418864","group":"CHAT","ltt":1292598006741,"sid":"755563549194447187","igds":"1290627502757","exempt":false}^inq|{"customerID":"755562378269271622"}^saleMgr|{"state":"UNSOLD","qDat":{},"sDat":{}}; inqState=sLnd|1^Lnd|{"c":4,"flt":1274728016,"lldt":17869990,"pgs":{"201198":{"c":1,"flt":1274728016,"lldt":0},"0":{"c":3,"flt":1274845009,"lldt":17752997}},"pq":["0","0","0","201198"],"fsld":1274728016697}; adv_search_results_page=10; ep_beta=1; visitorID=57307059; JSESSIONID=6jXLNdHRDjR9Th3B5gvTVkw1dZLn1zvhvKLR2r4GTLjylHJgjY3Q!683274050; __utmc=156962862; JSESSIONID=6jXLNdHRDjR9Th3B5gvTVkw1dZLn1zvhvKLR2r4GTLjylHJgjY3Q!683274050; TLTHID=5CCA50304DE99E28DB79A7B3267D4231; TLTSID=9DFCDE8045B374AAB752CC98A30E8311; AreCookiesEnabled=1; s_cc=true; SC_LINKS=%5B%5BB%5D%5D; s_sq=%5B%5BB%5D%5D; __utmb=156962862.64.10.1297958674; memberexists=T; ev1=greywolf%20hdtv%20whmx
Cache-Control: max-age=0
HTTP/1.0 200 OK
Date: Thu, 17 Feb 2011 17:38:44 GMT
X-Powered-By: Servlet 2.4; JBoss-4.2.1.GA (build: SVNTag=JBoss_4_2_1_GA date=200707131605)/Tomcat-5.5
Content-Encoding: gzip
Content-Type: text/html;charset=UTF-8
Content-Length: 24739
X-Cache: MISS from samus.company.com
X-Cache-Lookup: MISS from samus.company.com:3128
Via: 1.0 samus.company.com:3128 (squid/2.6.STABLE20)
Proxy-Connection: keep-alive
----------------------------------------------------------
Addendum 2: Additional Information
浏览器确实收到了“gzipped”文件 . 当我发现其中一些错误时,我之前点击过“另存为...” . Gunzip成功处理了文件并将其转换为html .
6 回答
答案在这里:How to preserve the Content-Type header of a Tomcat HTTP response sent through an AJP connector to Apache using mod_proxy
在apache配置中将DefaultType设置为None .
第一页下载是mime类型“application / octet-stream” . 可能正在将压缩流发送回浏览器? (您可以通过保存文件并查看其中来确认 . )
对于有问题和正常的情况发布Live HTTP Header请求/响应跟踪会非常有用 . 如果内容在两种情况下都相同 - 响应HTML - 可能强制mime类型为text / html(使用ForceType指令),因为该特定上下文可以解决问题 .
如果事实证明在有问题的情况下将gzip压缩内容发送到浏览器 - 则需要深入挖掘 . 这个浏览器是否具体 - 仅适用于Firefox或适用于所有浏览器?
好的,根据提供的新信息 - 看起来Squid正在缓存有问题的响应,而不是将正确的标头发送回客户端 . 所以浏览器在这里做正确的事情 - 没有内容编码和正确的内容类型,他们不能做太多其他事情 .
缺少有问题请求的响应头:X-Powered-By:Servlet 2.4; JBoss-4.2.1.GA(build:SVNTag = JBoss_4_2_1_GA date = 200707131605)/Tomcat-5.5 Content-Encoding:gzip Content-Type:text / html; charset = UTF-8
X-Powered-By:听起来有问题的请求实际上没有击中你的JBoss服务器 . 你能通过检查访问日志来验证这一点吗? Squid缓存响应然后以text / plain发送回来吗?
重新配置Squid以不缓存该特定URL应该有帮助 - 例如,参见http://www.lirmm.fr/doc/Doc/FAQ/FAQ-7.html第7.8节(特定于Squid 2但后来的版本应该具有类似的功能 . )
似乎是内容协商问题 . Apache使用"magic"字节猜测内容类型并错误地设置内容类型 . 这就解释了为什么它会间歇性地发生 . 尝试禁用mod_negotiation并查看会发生什么 . 有关详细信息,请参阅http://httpd.apache.org/docs/2.0/content-negotiation.html .
我在你的设置中看到了以下内容
但端口8080不是ajp端口 . 默认的ajp端口是 8009 . 这可能是你的问题吗?
您的Web应用程序很可能出现问题,而不是Apache . 如果您的网络应用程序发送回来正确的Content-Type,Apache很乐意将它转发给客户端 . 在这种情况下,不会进行内容协商 . 如果你没有返回任何Content-Type,Apache几乎肯定会替换text / plain,这不是你想要的 .
在中间没有Apache的情况下测试您的Web应用程序,确保它发送回正确的Content-Type .
它用于当apache在非安全通道中提供安全内容时 .