阿帕奇 gzip SOAP

Apache gzip SOAP

我是 Apache 的新手,我正在尝试弄清楚如何启用 gzip 压缩以将数据发送到客户端(.NET Compact Framework 设备)。 我使用的是 Apache 2.2,到目前为止,我已经启用了 mod_deflate.so,但是我通过网络发送的内容没有被 gzip 压缩。 任何的想法?非常感谢

更新 我正在 Windows 使用 Apache 2.2。在我的 httpd.conf 文件中,我取消了这一行的注释。

LoadModule deflate_module modules/mod_deflate.so

我的模块位置在 httpd.conf 文件中,如下所示:

<Location /MyModule>
    SetHandler mod_MyModule-handler
</Location>

并且在 httpd.conf 文件中,我已经有了所有这些,所以除了我取消注释 DeflateCompressionLevel 9 之外,这里没有任何改变:

<Location />
    # Insert filter
    SetOutputFilter DEFLATE

    # compress text, html, javascript, css, xml:
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/json
    AddOutputFilterByType DEFLATE application/x-javascript

    #DeflateCompressionLevel 9  //if I uncomment this, server wont start
    # 1 to 9: 9 is the most compressed

    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html

    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip

    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
    # the above regex won't work. You can use the following
    # workaround to get the desired effect:
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    #The following statement indicate which document types not to compress. Many type of documents do not compress well.
    #At the end (Appendix 1) of this article some more type you might wish to also exclude from compression
    # Don't compress images
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary

    # Make sure proxies don't deliver the wrong content
    # install/enable the Apache module mod_headers
    Header append Vary User-Agent env=!dont-vary

    # install/enable the Apache module LoadModule expires_module modules/mod_expires.so
    # turn on the module for this directory
    ExpiresActive on

    # set defaults
    ExpiresByType text/javascript "modification plus 11 months"
    ExpiresByType application/javascript "modification plus 11 months"
    ExpiresByType text/css "modification plus 11 months"

</Location>

然后我重新启动 Apache,向它发送请求并收到响应,但是 response.ContentEncoding 没有在 .NETCF 客户端中显示 "gzip"。看来我少了什么。

取消注释 deflate 模块

    LoadModule deflate_module modules/mod_deflate.so

并像这样将此节添加到 virts 配置中(确保包含您的 soap mime 类型)

<IfModule deflate_module>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

bash 测试

function check_compression {
  curl -s -k -I -H 'Accept-Encoding: gzip,deflate'  |grep "Content-Encoding"
}

check_compression  http://your.url.com

如果这不起作用,请检查您是否为 soap 响应正确设置了 mime 类型。