2

mod_proxy_ajp 发生了一个奇怪的间歇性错误,即使用 apache 作为 tomcat 服务器的前端。

错误

  • 用户单击链接浏览器提示用户“另存为...”(例如,在 Firefox 中“您已选择顶部打开的 thread.jsp 这是一个应用程序/八位字节流”...firefox 应该如何处理此文件)
  • 用户说“嗯?” 并按“取消”
  • 用户再次点击同一链接
  • 浏览器正确显示页面

此错误间歇性发生,但不幸的是在我们的测试服务器上很少发生,而在生产中经常发生。

在 Firefox 的 LiveHttpHeaders 中,我在上述用例中看到以下内容:

  • 第一页下载(即点击链接)是“文本/纯文本”
  • 第二次下载是“text/html”

我认为问题可能源于 ProxyPassReverse(即混淆是使用 http 还是 ajp),但是所有这些 proxypassreverse 设置都导致了相同的错误:

此外,我检查了 apache 错误日志(设置为调试),没有看到任何警告或错误...

** 但它适用于 mod_proxy_http ?? **

切换到 mod_proxy_http 似乎“解决”了这个问题。有限的测试,我无法在测试环境中重现问题。

因为问题是间歇性的,我不能 100% 确定 mod_proxy_http “解决”了问题

环境

  • 阿帕奇 2.2 视窗
  • Jboss 4.2.2 后端(tomcat 6)

另一个数据点

无论好坏,tomcat 中的 servlet 过滤器都会先压缩 html,然后再将其发送到 apache。(这意味着额外的工作,因为 apache 必须在执行 ProxyPassReverse 的“查找和替换”之前解压缩)。我不知道“gzip”是否搞砸了。

问题

  • 有人见过这个吗?
  • 哪些工具有助于分析原因?

谢谢

附录 1:这是 LiveHttpHeaders 输出

浏览器错误地将 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: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
----------------------------------------------------------

附录 2:附加信息

浏览器确实收到了“gzipped”文件。当其中一些错误发生时,我早些时候点击了“另存为...”。Gunzip 成功处理了这些文件并将它们转换为 html。

4

6 回答 6

5

答案在这里:如何使用 mod_proxy 保留通过 AJP 连接器发送到 Apache 的 Tomcat HTTP 响应的 Content-Type 标头

在 apache 配置中将 DefaultType 设置为 None。

# DefaultType: the default MIME type the server will use for a document
# if it cannot otherwise determine one, such as from filename extensions.
# If your server contains mostly text or HTML documents, "text/plain" is
# a good value.  If most of your content is binary, such as applications
# or images, you may want to use "application/octet-stream" instead to
# keep browsers from trying to display binary files as though they are
# text.
#
DefaultType None
于 2012-01-10T16:25:19.220 回答
0

There is most likely something wrong with your web application, not Apache. If your web app sends back the correct Content-Type, Apache will gladly forward it to the client. No content negotiation will be done in that case. If you do not return any Content-Type, Apache will almost surely substitute text/plain, which is not what you want.

Test your web app without Apache in the middle, make sure that it sends back the correct Content-Type.

于 2012-02-21T16:53:16.153 回答
0

似乎是一个内容协商问题。Apache 使用“魔术”字节猜测内容类型并错误地设置了内容类型。这就解释了为什么它会间歇性地发生。尝试禁用 mod_negotiation 看看会发生什么。有关详细信息,请参阅http://httpd.apache.org/docs/2.0/content-negotiation.html

于 2011-02-26T05:47:54.560 回答
0

我在您的设置中看到了以下内容

ProxyPassReverse /ajp://localhost:8080/

但是 8080端口不是ajp 端口。默认的 ajp 端口是8009。这可能是你的问题吗?

于 2011-02-26T20:28:14.607 回答
0

第一页下载是 mime 类型“application/octet-stream”。可能是压缩流被发送回浏览器?(您可以通过保存文件并查看其中来确认。)

对于有问题的和正常的情况,发布 Live HTTP Header 请求/响应跟踪会非常有帮助。如果两种情况下的内容相同 - 响应 HTML - 可能会针对该特定上下文强制 mime 类型为 text/html(使用 ForceType 指令)可以解决问题。

如果事实证明,在有问题的情况下,gzip 压缩的内容被发送到浏览器 - 那么深入挖掘是必要的。这个浏览器是特定的 - 只发生在 Firefox 上还是发生在所有浏览器上?

好的,根据提供的新信息 - 看起来 Squid 正在缓存有问题的响应,并且没有将正确的标头发送回客户端。所以浏览器在这里做的是正确的事情——没有 Content-Encoding 和正确的 Content-Type 他们不能做很多其他事情。

有问题的请求缺少响应标头:X-Powered-By: Servlet 2.4;JBoss-4.2.1.GA (build: SVNTag=JBoss_4_2_1_GA date=200707131605)/Tomcat-5.5 内容编码: gzip 内容类型: text/html;charset=UTF-8

X-Powered-By :听起来有问题的请求实际上并没有命中您的 JBoss 服务器。您可以通过检查访问日志来验证这一点吗?Squid 是否缓存响应,然后将其作为文本/纯文本发送回?

重新配置 Squid 以不缓存该特定 URL 应该会有所帮助 - 例如,请参见http://www.lirmm.fr/doc/Doc/FAQ/FAQ-7.html第 7.8 节(这是 Squid 2 特有的,但更高版本应该有类似的能力。)

于 2011-02-17T20:34:17.750 回答
0

它曾经是 apache在非安全通道中提供安全内容的时候。

于 2011-02-27T20:06:45.483 回答