如何使用mod_proxy保存通过AJP连接器发送到Apache的Tomcat HTTP响应的Content-Type标头

tsb*_*nes 7 apache proxy tomcat axis2 content-type

我在Content-Type通过AJP/1.3连接器访问Apache后面的Tomcat中托管的Axis2 Web服务时遇到了错误的HTTP响应标头问题.

我可以通过其RESTful接口在浏览器中无问题地访问Web服务,我可以看到结果,但不知何故Apache正在更改Content-TypeTomcat发送的响应头text/xml,text/plain并且它阻止我通过NetBeans中的SOAP来使用Web服务,因为一个Unsupported Content-Type: text/plain Supported ones are: [text/xml]例外.

这是我的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>
Run Code Online (Sandbox Code Playgroud)

以及我的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" />
Run Code Online (Sandbox Code Playgroud)

如果我使用端口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
Run Code Online (Sandbox Code Playgroud)

线到

ProxyPass http://localhost:8080/axis2/services
ProxyPassReverse http://localhost:8080/axis2/services
Run Code Online (Sandbox Code Playgroud)

Dan*_*gio 9

# 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
Run Code Online (Sandbox Code Playgroud)

这是解决方案.在httpd.conf中查看这一部分,重要的是DefalutType是None.如果你看到普通/文本这就是问题所在.对不起,这个解决方案不是我的,但我不知道我找到了哪个博客:-)


小智 2

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

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

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

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

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