【问题标题】:How to preserve the Content-Type header of a Tomcat HTTP response sent through an AJP connector to Apache using mod_proxy如何使用 mod_proxy 保留通过 AJP 连接器发送到 Apache 的 Tomcat HTTP 响应的 Content-Type 标头
【发布时间】:2011-03-24 21:33:13
【问题描述】:

在通过 AJP/1.3 连接器访问托管在 Apache 后面的 Tomcat 中的 Axis2 Web 服务时,我遇到了 HTTP Response Content-Type 标头不正确的问题。

我可以通过其 RESTful 界面在浏览器中毫无问题地访问 Web 服务,我可以看到结果,但不知何故 Apache 正在将 Tomcat 发送的响应 Content-Type 标头从 text/xml 更改为 text/plain,它阻止了我由于Unsupported Content-Type: text/plain Supported ones are: [text/xml] 异常,无法通过 NetBeans 中的 SOAP 使用 Web 服务。

这是我的 Apache vhosts 配置的相关部分:

<VirtualHost *:80>
    ServerAdmin me@myserver.example
    ServerName  myserver.example
    ServerAlias other.myserver.example

    ProxyPreserveHost On 
    SetEnv force-proxy-request-1.0 1
    SetEnv proxy-nokeepalive 1

    <Location /axis2/services>
        ProxyPass ajp://localhost:8009/axis2/services
        ProxyPassReverse ajp://localhost:8009/axis2/services
    </Location>
</VirtualHost>

还有我的Tomcat server.xml的相关部分:

<Connector port="8009" protocol="AJP/1.3" redirectPort="9443" />

<Connector port="9443" protocol="HTTP/1.1" SSLEnabled="true" maxHttpHeaderSize="8192"
    maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
    enableLookups="false" disableUploadTimeout="true"
    acceptCount="100" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS"
    SSLCertificateFile="path/to/bundle" 
    SSLCertificateKeyFile="path/to/key"
    SSLPassword="S3cr3t"
    proxyName="myserver.example" proxyPort="443" />

如果我使用端口 8080 上的默认连接器直接在 Tomcat 中访问 WS,我会得到正确的 content-type,但如果我通过 Apache 访问它,则会得到 text/plain,所以这肯定是代理的问题。

我该如何解决这个问题?

编辑:我使用 Tomcat HTTP 连接器进行代理而不是 AJP 连接器,但如果找到可行的解决方案,我更愿意使用 mod_ajp。

我刚换了

ProxyPass ajp://localhost:8009/axis2/services
ProxyPassReverse ajp://localhost:8009/axis2/services

行到

ProxyPass http://localhost:8080/axis2/services
ProxyPassReverse http://localhost:8080/axis2/services

【问题讨论】:

  • markmail.org/message/… 似乎与您的问题有关
  • 是的,这是同一个问题,我已经找到了一些类似 2007 年的邮件存档,然后在这里发布问题,但我仍然找不到解决这个问题的方法。

标签: apache tomcat proxy content-type axis2


【解决方案1】:
# 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

这就是解决方案。 查看httpd.conf中的这一部分,DefalutType为None很重要。 如果您看到纯文本/文本,这就是问题所在。 抱歉,这个解决方案不是我的,但我不知道我在哪个博客中找到它:-)

【讨论】:

  • 谢谢。代理遇到了 401 问题。这有效!
【解决方案2】:

过去两天我一直在工作中寻找类似的东西。

过去在 Apache HTTPD 和 Tomcat 中都出现过一些产生类似问题的错误,但大多数似乎至少在 2 年前就已经解决了。我认为这是任何使用当前软件的人都可能遇到的问题 - 这当然是我目前正在经历的:

https://issues.apache.org/bugzilla/show_bug.cgi?id=49929

Tomcat 7.x 中可能有补丁,但还没有人测试过。 我计划在大约一周内有时间时这样做,并生成一个可靠的测试用例,以便可以在所有相关版本的 tomcat 中修复此问题。

这仅在使用 APR 时发生,因此一种中间解决方案是避免这种情况(但这可能会对性能产生影响)。

【讨论】:

    【解决方案3】:

    这解决了我的头痛问题。我有 Apache 2.2 作为前端,mod_proxy_ajp 和 jboss 作为后端。几笔交易失败

    Message: Client found response content type of 'text/plain; charset=UTF-8', but expected 'text/xml'.
    

    我的 Apache 确实有 'text/plain' 作为 DefaultType。但是,我没有在全局级别(httpd.conf)更改此设置。我在&lt;proxy&gt; 配置部分中为我的虚拟主机配置添加了一个新行,将其设置为text/xml

    DefaultType text/xml
    

    我确实尝试使用 None 对我不起作用,然后我得到了:

    '' in the error msg instead of 'text/plain'.
    

    【讨论】:

      猜你喜欢
      • 2017-04-26
      • 2013-05-27
      • 1970-01-01
      • 2010-10-31
      • 2013-09-30
      • 2012-11-01
      • 2016-07-04
      • 2015-04-17
      • 2022-06-25
      相关资源
      最近更新 更多