Apache 错误地将 jsp 页面转换为 "text/plain"

标签 apache tomcat ajp

我有一个相当正常的设置,其中 Apache 通过 AJP 协议(protocol)代理对 Tomcat 内运行的 servlet 的请求。

我们已经在 Apache 2.0.46/Tomcat 5.0.28 上运行此设置很长时间没有出现问题,但最近已更新到 Apache 2.2.3/Tomcat 5.5。

问题是我们注意到 Apache 间歇性地(可能是 3 次)会以某种方式将 servlet 服务的页面的“Content-Type”HTTP header 从“text/html”转换为“text/plain” ",这会导致浏览器显示 HTML 源代码而不是呈现它。

有没有人以前见过这种行为并且知道可能是什么原因?我怀疑我们在旧版本的 Tomcat/Apache 更宽容的 servlet 代码中做了一些不好的事情。

更新:我已经确认是 Apache 更改了 header 。如果我直接浏览到 Tomcat,则不会出现该问题。

最佳答案

一些网络应用程序没有正确设置它们提供的内容的 mime 类型,但在独立提供时仍然可以正常工作,因为像浏览器这样的客户端应用程序能够解释内容的类型。但是,当在 Apache 后面提供服务时,这些应用程序将无法正常运行,因为 Apache 将提供默认类型的文本/纯文本。

解决方案是为这些 Web 应用程序添加 DefaultType None 行到您的 Apache 虚拟主机:

DefaultType None

http://httpd.apache.org/docs/2.2/mod/core.html#defaulttype

来 self 的博文: http://patternbuffer.wordpress.com/2011/11/30/mime-type-issue-with-apache-mod_jk-and-mod_proxy-serving-plain-text/

关于Apache 错误地将 jsp 页面转换为 "text/plain",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/933959/

相关文章:

spring - 如何通过 RestTemplate 调用透明地传播 HTTP header ?

WAR 存档中的 Java 编辑文件

python - 使用 Flask、Flask 登录、mod-wsgi 切换到 wsgi 时登录停止工作

apache - "The machine with the name ' c6401 ' was not found configured for this Vagrant environment."错误

java - WebSocket握手时出错: Unexpected response code: 404

apache - 使用 mod_proxy_ajp 在端口 80 上运行 tomcat(错误)

tomcat - 部署Spring boot app jar文件嵌入tomcat

tomcat - Spring Security 和 AJP 代理

tomcat - Tomcat中如何设置AJP包大小?

系统重新启动后,带有 mod_jk 的 apache2 tomcat7 无法工作