apache - mod_proxy_ajp错误: renders html as text/plain,提示用户 "save as..."

标签 apache tomcat mod-proxy ajp

我们在 mod_proxy_ajp 中遇到了一个奇怪的间歇性错误,即使用 apache 作为 tomcat 服务器的前端。

错误

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

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

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

  • 首页下载(即点击链接)是“text/plain”
  • 第二个下载是“text/html”

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

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

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

看来切换到 mod_proxy_http 可以“解决”该问题。有限的测试,我无法在测试环境中重现该问题。

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

环境

  • Apache 2.2 Windows
  • Jboss 4.2.2 后端 (tomcat 6)

另一个数据点

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

问题

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

谢谢

附录 1:这是 LiveHttpHeaders 输出

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

附录 2:附加信息

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

最佳答案

答案在这里: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。

# 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

关于apache - mod_proxy_ajp错误: renders html as text/plain,提示用户 "save as...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5034131/

相关文章:

Apache 从子域重写为 www 但保留所有永久链接

php - Apache 2.4 + php-fpm - AH01071 : Got error 'Primary script unknown\n' mod_proxy_balancer

apache2 - 收到带有签名的 Ajp 无效消息

apache - Tomcat 集群环境中的 JDBC 连接池

php - .htaccess中的php_value显示内部服务器错误

apache - 如何获取默认的 Apache getting-started.html?

java - Apache 服务器作为 Jboss 问题的代理

Tomcat 中的 HTML Href

java - Gradle tomcat 插件和属性文件

tomcat - 删除 tomcat 中的临时文件夹和工作文件夹会损坏我的安装