Apache, Tomcat and Gzip

I wanted GZipped packets arriving at the Apache Http Server to be uncompressed and redirected to Tomcat. I am now using :

  • mod_proxy_http, to connect Apapche with Tomcat and
  • mod_deflate, to uncompress incoming requests.

I am running a Ubuntu. Let us say we are running a webapp at http://localhost:8080/test. I did the following to setup my system:

I enabled the mods.

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod deflate

I edited proxy.conf.

sudo vim /etc/apache2/mods-enabled/proxy.conf

I added these lines:

ProxyPass / http://localhost:8080/test/
ProxyPassReverse / http://localhost:8080/test/

I edited deflate.conf.

sudo vim /etc/apache2/mods-enabled/proxy.conf

All I added here was:

<Location /url/to/uncompress/requests/for>
        SetInputFilter DEFLATE

Well, that's it. Finally, run:

sudo /etc/init.d/apache2 restart

Details: My Story

Well, first thing is to decide which approach to take to connect Apache and Tomcat. I found three options:

  • mod_jk
  • mod_proxy_http
  • mod_proxy_ajp

There are comprisons between the three:

  • http://www.tomcatexpert.com/blog/2010/06/16/deciding-between-modjk-modproxyhttp-and-modproxyajp
  • http://stackoverflow.com/questions/1081918/apache-to-tomcat-mod-jk-vs-mod-proxy
  • http://higherlogic.com.au/2010/http-vs-mod_proxy_ajp-vs-mod_jk-part-1-speed/

I went for mod_jk. However, in combination with mod_deflate, this does not work since mod_deflate does not change the Content-Length header field after uncompressing. This results in the uncompressed content being longer than specified by the Content-Length. mod_jk will then only send data to Tomcat until the output reaches the Content-Length. The rest of the message is truncated.

This behvior is filed as a bug:

VN:F [1.9.22_1171]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Leave a Reply