Using mod gzip to improve MythWeb performance

From MythTV Official Wiki
(Redirected from ApacheModGzipHowTo)
Jump to: navigation, search

Important.png Note: This guide is for apache 1.x, if you're using apache 2.x you will want to look into mod_deflate.

I run mythweb on my home internet connection, and unfortunately my upload rate is only 300kbps. I have all my channels set to be listed in the mythweb listings (including audio channels) and the listings page comes out to about 1.1MB in size. 1.1MB takes about 30 seconds at 300kbps and if my connection was already being utilized for something else my listings could take over a minute to load.

This became frustrating and I decided to setup mod_gzip for apache. The install was actually pretty easy. The first thing that needs to be accomplished is to make sure mod_gzip is installed. I use debian, so I ran:

apt-get install libapache-mod-gzip

For Fedora or Redhat users you will need to use yum or apt to install the proper package.

Next I edited /etc/apache/httpd.conf (Fedora users will probably have it in /etc/httpd/conf/httpd.conf). The debian package automatically added an entry in /etc/apache/modules.conf to load the module, but fedora users may need to add this (near the top by the other [[Load Module]] statements) to /etc/httpd/conf/httpd.conf.

[[Load Module]] gzip_module /usr/lib/apache/1.3/

Once that was done it was just a matter of configuring mod_gzip. Since this machine only serves up mythweb I turned on mod_gzip for everything. However, if your machine serves up other pages you may want to set this up for only certain directories or virtual hosts.

I put the following lines near all the other [[If Module]] sections:

Script.png part of /etc/httpd/conf/httpd.conf

   <[[If Module]] mod_gzip.c>
 # use mod_gzip at all?          
   mod_gzip_on                   Yes
 # let mod_gzip perform 'partial content negotiation'?
   mod_gzip_can_negotiate        Yes
 # ---------------------------------------------------------------------
 # extension (suffix) for statically precompressed files
   mod_gzip_static_suffix        .gz
   [[Add Encoding]]              gzip .gz
 # automatic updates for statically precompressed files
   mod_gzip_update_static        No
   mod_gzip_command_version      '/mod_gzip_status'
 # Save temporary work files [Yes, No]
   mod_gzip_keep_workfiles       No
   mod_gzip_minimum_file_size    500
   mod_gzip_maximum_file_size    5000000
 # ---------------------------------------------------------------------
 # maximum size (in bytes) for files to be compressed in memory
   mod_gzip_maximum_inmem_size   200000
   mod_gzip_min_http             1000 
   mod_gzip_handle_methods        GET POST  
   mod_gzip_item_exclude         reqheader  "User-agent: Mozilla/4.0[678]"
 # JA:   HTML-Dokumente                       
   mod_gzip_item_include         file       \.html$
   mod_gzip_item_include         file       \.php$
   mod_gzip_item_include         file       \.php3$
 # NO:   include files / [[Java Script]] & CSS (due to Netscape4 bugs)
   #mod_gzip_item_exclude         file       \.js$
   #mod_gzip_item_exclude         file       \.css$
 # YES:  CGI scripts             
   mod_gzip_item_include         file       \.pl$
   mod_gzip_item_include         handler    ^cgi-script$
 # phase 2: (mime, rspheader)
 # ===========================
 # YES:  normal HTML files, normal text files, Apache directory listings
   mod_gzip_item_include         mime       ^text/html
   mod_gzip_item_include         mime       ^text/plain$
   mod_gzip_item_include         mime       ^httpd/unix-directory$
 # NO:   images (GIF etc., will rarely ever save anything)
   #mod_gzip_item_exclude         mime       ^image/
 # ---------------------------------------------------------------------
   mod_gzip_dechunk              Yes
   [[Log Format]]                     "%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_ra
 # ---------------------------------------------------------------------
   [[Custom Log]]                     /var/log/httpd/mod_gzip.log common_with_mod_gzip_info2
   mod_gzip_add_header_count     Yes
   mod_gzip_send_vary            Yes
 # (see chapter about caching for this directive.)
 #  don't change this unless you absolutely know what you are doing!
 # ---------------------------------------------------------------------
   </[[If Module]]>

However, putting it anywhere near the top or middle of the config file should work.

Next tail the mod_gzip log file:

# tail -f /var/log/httpd/mod_gzip.log

Now goto your mythweb listings in your browser and you should see something like this show up in your mod_gzip log:

[10/Feb/2005:10:45:10 -0700] "localhost GET /program_listing.php HTTP/1.1" 200 77037 mod_gzip: DECHUNK:OK In:1103726 -< Out:76448 = 94 pct.

If you got anything other than DECHUNK:OK you can view a list of status codes at

Using mod_gzip cut my load time down to about 3-10 seconds.