Potty Page

May 3, 2005

mod_gzip: things getting quicker?

For your speedy downloading fun I've installed the Apache module mod_gzip onto the server.

What, prey tell, is this? I hear you asking. Simple really. Before compressable things - like text are sent to your webbrowser, they are compressed here at server. This means that they are smaller to download and, in theory, therefore download quicker. At your end the compressed data is simply inflated again by your browser, so you can read it.

Clearly, this has CPU cost associated with it, but, I hope it won't actually be that noticable!

I had some issues actaully getting it to function at all. This was slightly, annoying, shall we say? If you're having issues with it yourself. Enable logging of the gzip stuff with something like...

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/gzip-access.log common_with_mod_gzip_info2

...in your httpd.conf file. This'll cause Apache to log all the requests with a status code. A description of these codes can be found all over the web by using a search engine. One I've found is at HowtoForge

Anyways... the status I was getting for things I thought should have been compressed was SEND_AS_IS:RESPONSE_CONTENT_TYPE_EXCLUDED. This was because I'd followed the instuctions on how to alter my configuration... which seem to be wrong...

The instuctions had me adding a line such as:

mod_gzip_item_include mime ^text/html$

The $ at the end means "end of the line", but after text/html it's no the end of the line... as there is a ; (semi-colon) after it when the server looks at it. Therefore as the content type doesn't match, it doesn't compress it. I've put the section of the code that works (for me) in the hope that it'll help somebody else!

<IfModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_can_negotiate Yes
  mod_gzip_static_suffix .gz
  mod_gzip_update_static No
  mod_gzip_command_version '/mod_gzip_status'
  mod_gzip_temp_dir /tmp
  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_min_http 1000
  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 \.shtml$
  mod_gzip_item_include file \.htm$
  mod_gzip_item_include file \.shtm$
  mod_gzip_item_include file \.php$
  mod_gzip_item_include file \.phtml$
  mod_gzip_item_exclude file \.js$
  mod_gzip_item_exclude file \.css$
  mod_gzip_item_include file \.pl$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/html;
  mod_gzip_item_include mime ^text/plain;
  mod_gzip_item_include mime ^httpd/unix-directory;
  mod_gzip_item_exclude mime ^image/
  mod_gzip_dechunk Yes
  mod_gzip_add_header_count Yes
  mod_gzip_send_vary Yes
</IfModule>

Good luck!

Posted by Ed at May 3, 2005 9:13 PM | Geek |