gzip compression using mod_deflate apache with tomcat – Problems with loading a website are often blamed on the Internet connection, but even the most perfectly set up network cannot help if there is no service to reply at your destination. One of the most popular HTTP servers used for this task is Apache2. Much of Apache’s popularity can be attributed to its easy installation and use, but never the less it is possible to run into problems with even the easiest of the software. If you’ve encountered an issue loading your web page, follow these simple troubleshooting methods outlined in this guide to attempt to get your web server back up and working again. Below are some tips in manage your apache2 server when you find problem about apache-2.2, tomcat, compression, mod-deflate, .
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.
You need to enable compression on Tomcat not on httpd for content served by Tomcat.