0

I am new to Apache and I am trying to figure out how to enable gzip compression to send data over to clients (.NET Compact Framework devices). I am using Apache 2.2 and so far, I have enabled mod_deflate.so but my content send over netwrok is not gzipped. Any idea? much appreciated

UPDATE I am on Windows using Apache 2.2. In my httpd.conf file, I uncommented this line.

LoadModule deflate_module modules/mod_deflate.so

My module Location is in httpd.conf file like this:

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

And in httpd.conf file, I already had all this, so nothing was changed here except that I have uncommented 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>

Then I restart Apache, send request to it and receive response but response.ContentEncoding does not show "gzip" in .NETCF client. It looks like I am missing something.

pixel
  • 9,653
  • 16
  • 82
  • 149

1 Answers1

1

uncomment the deflate module

    LoadModule deflate_module modules/mod_deflate.so

and add this stanza to the virts config like this (be sure to include your soap mime type)

<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 test

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

check_compression  http://your.url.com

If that doesn't work, check that you have the mime type set correctly for the soap response.

Kevin Seifert
  • 3,494
  • 1
  • 18
  • 14
  • Thanks user1389596. I updated my post to show what I have set. It looks like I have already everything set but I am not getting anything gzipped on client. Also, I am on Windows, so cannot do bash test – pixel Aug 12 '15 at 22:50
  • 1
    I'd start off with a simpler config file. For example, comment out everything but the mime type lines. The thing I'd check is the mime type that the SOAP response is sending as. If that doesn't work, my guess is the request perhaps is not sending through the / location. Are there any virtual hosts defined? I typically put the config in the virtualhost stanza – Kevin Seifert Aug 13 '15 at 01:41
  • Hi Kevin, the ContentType is "text/xml". There are no virtual hosts defined. Would you mind explaining what do you mean by "...not sending through the / location."? I am new to all this and need more info. The I provided above is exactly how it is currently all being set. I have also updated post to provide more info how is set for my module, please take a look. Are you saying I should move what is in to the of my module ? – pixel Aug 13 '15 at 17:38
  • 1
    The problem could be that the configuration in is completely being ignored based on how the request is being processed. Typically I either will put configuration at the global level (outside of the Location stanza) or inside a VirtualHost stanza: http://httpd.apache.org/docs/2.2/vhosts/examples.html If you have another Location stanza for your service, add all the configuration there (closest to the point where your specific service configuration is) – Kevin Seifert Aug 13 '15 at 17:53
  • I tried moving it outside of the Location and I was putting it in the Location of my module. Neither will start Apache. If I leave them in Location / then I can start apache but there is no gzip in response – pixel Aug 13 '15 at 18:06
  • That is good news, to some degree. If you move it to the Location tag of your module and apache doesn't start, then it means apache is definately reading the configuration. The logs/ might have some more details. When I look at the context for the options, I don't think AddOutputFilterByType can go in a location stanza. It looks like it should be placed in one of the following contexts: server config, virtual host, directory, .htaccess. I'd set this up as a virtualhost instead if possible. From http://httpd.apache.org/docs/2.2/mod/core.html#addoutputfilterbytype – Kevin Seifert Aug 13 '15 at 18:55
  • Interesting, looking at the same link, the example is using it inside Location stanza and being valid in Directory context means it is valid in , , , .. – pixel Aug 13 '15 at 19:59
  • Ah, I was misreading the context. Do you have a tag wrapping the stanza? I wonder if the module is not available? – Kevin Seifert Aug 13 '15 at 20:07
  • It should be available, it is returned by httpd -M as: deflate_module (shared) and so does httpd -D DUMP_MODULES – pixel Aug 13 '15 at 20:17
  • Turns out that client needed to set this in request request.Headers["Accept-Encoding"] = "gzip, deflate";. After that, enabling mod_deflate will send gzipped content – pixel Aug 14 '15 at 17:24
  • Thanks for your help Kevin, much appreciated – pixel Aug 14 '15 at 18:01
  • Yeah, now have another problem, figuring out how to decmompress it on client side in .NET CF 3.5 – pixel Aug 14 '15 at 21:52