Thursday, December 14, 2006

mod_gzip for Apache

Apache's mod_gzip provides good compression for server output. I just got it working on my server with little bit of tweaking done in the configuration. I was using the debian server.

Install mod_zip if you don't have it already:

apt-get install libapache-mod-gzip

Load the module mod_gzip: (add this line in httpd.conf or modules.conf)
LoadModule gzip_module /usr/lib/apache/1.3/
Look at the example configuration file.

Here is the configurtaion I added:
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_can_negotiate Yes
mod_gzip_static_suffix .gz
AddEncoding gzip .gz
mod_gzip_command_version '/mod_gzip_status'
mod_gzip_keep_workfiles No
mod_gzip_minimum_file_size 500
mod_gzip_maximum_file_size 500000
mod_gzip_maximum_inmem_size 60000
mod_gzip_handle_methods GET POST

mod_gzip_item_exclude reqheader "User-agent: Mozilla/4.0[678]"

mod_gzip_item_include file \.html$

mod_gzip_item_include file \.js$
mod_gzip_item_include file \.css$

mod_gzip_item_exclude mime ^image/
mod_gzip_item_include mime ^text/

# This was very important to get things working
mod_gzip_item_include uri .*

mod_gzip_dechunk Yes

LogFormat "%h %l %u %t \"%V %r\" %<s %b
mod_gzip: %{mod_gzip_result}n In:%{mod_gzip_input_size}n -<
Out:%{mod_gzip_output_size}n = %{mod_gzip_compression_ratio}n
pct." common_with_mod_gzip_info2

CustomLog /var/log/apache/mod_gzip.log common_with_mod_gzip_info2
I had to add the configuration line mod_gzip_item_include uri .* until then I saw only mod_gzip: DECLINED:EXCLUDED In:0 -< Out:0 = 0 pct. in the mod_zip.log.
Look at which reports problem with mod_gzip and mod_ssl, so added this line of configuration as well. Add this only if you enabled ssl access for your server.

<VirtualHost *:443>
<IfModule mod_ssl.c>

<IfModule mod_gzip.c>
mod_gzip_on No

NOTE: With Apache2 you can use mod_deflate for the gzip compression. To get more details look at

Locale Dependent DateFormat

Recently I came across a strange problem on the debian server install.

The following piece of jython code which was working fine on my machine failed to work on debian server.

import java.text.DateFormat as DateFormat
format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
print format.parse('Nov 6, 2006 3:23:54 PM');

I was getting this exception:
Traceback (innermost last):
File "<string>", line 5, in ?
java.text.ParseException: Unparseable date: "Nov 6, 2006 3:23:54 PM"
at java.text.DateFormat.parse(

I looked at the default Locale that was used and it was: [command used: locale]

I did the following and got the piece of code working:
export LC_CTYPE="en_US.UTF-8"
[If this does not solve try export LC_TIME="en_US.UTF-8"]

After this I could got the following output:
Mon Nov 06 15:23:54 IST 2006

Make sure you set the right LOCALE before using any API that depends on SYSTEM LOCALE information. Few Java API's allows you to specify the Locale as an argument use it when required.

More details about Java 1.3 Locale

I found a related post Don't forget to specify the locale

This page is powered by Blogger. Isn't yours?