1

I'm trying to enable gzip compression in my Apache server which is fronting a Tomcat instance using a connector. I tried several variants of the module configuration settings in my httpd.conf. Here is my latest attempt:

<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

DeflateCompressionLevel 9
SetEnvIfNoCase Request_URI \.(?:gif|png|jpg|jpeg)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio

LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog "/var/output/logs/deflate_log" deflate
ErrorLog "/var/output/logs/deflate_error_log"
</IfModule>

I'm checking the response headers using Firebug and I verified that the request headers have Accept-Encoding: gzip deflate but every time, the Content-Encoding header is missing from response.

I tried adding the following line to httpd.conf, but it is giving an error that mod_deflate is a built-in module and cannot be loaded. I confirmed this by apachectl -t and it shows mod_deflate.c as compiled module.

LoadModule deflate_module /usr/lib/apache2/modules/mod_deflate.so

I've a Tomcat instance that is connected to Apache via AJP connector. When I debugged my servlets, I found that the response Content-Type I'm getting for my test script is application/javascript;charset=UTF-8. I initially was using AddOutputFilterByType directive and thought that the additional charset=UTF-8 part might be messing up the MIME type for Apache, but then it isn't working with SetOutputFilter DEFLATE also.

My custom logs for deflate show the following line repeatedly:

GET /myservlet HTTP/1.1" -/- (-%)

I don't understand why this isn't working. My Apache version is 2.0.63. Did anybody face similar issue? Is there anyway I can debug further and check what is going on within Apache? Perhaps enabling some debug logging?

Thanks, Venkat.

Venkat
  • 111
  • 1
  • 2

1 Answers1

0

You need to enable compression on Tomcat not on httpd for content served by Tomcat.

Mark Thomas
  • 887
  • 5
  • 8
  • 1
    According to this post: [link](http://stackoverflow.com/questions/16653642/tomcat-7-gzip-compression-not-working), it seems if Tomcat is fronted by Apache, we need to do it on Apache and not Tomcat. I tried enabling compression on Tomcat, but it isn't working either. – Venkat Mar 18 '14 at 01:23
  • As an additional note, Tomcat is compressing data if I access it directly on its own port 8080. But when I go through Apache, it is not compressing the data. – Venkat Mar 18 '14 at 01:28