old-www/HOWTO/Apache-Compile-HOWTO/compress.html

414 lines
7.3 KiB
HTML

<HTML
><HEAD
><TITLE
>Compressed delivery</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Apache Compile HOWTO"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Additional modules"
HREF="modules.html"><LINK
REL="NEXT"
TITLE="mod_php and its prerequisites"
HREF="php.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Apache Compile HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="modules.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="php.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="COMPRESS"
></A
>5. Compressed delivery</H1
><P
>There are basically two modules available for output compression: mod_gzip and mod_gunzip. They are using different approaches
to reach the the goal of bandwidth reduction.</P
><P
>mod_gunzip expects compressed file on the filesystem, and uncompress them if the browser cannot handle compressed data.
The benefit is a low cpu-usage, because most browsers are capable to handle gzipped content. On the oder side, most of today's
content is served dynamically i.e. PHP, and this content will be delivered uncompressed.</P
><P
>mod_gzip does not need compressed files on the system, all defined content will be compressed before delivery. The benefit is
to have the dynamically generated content also compressed, the other side is a higher cpu-usage, because every request has to be
compressed on-the-fly. Mod_gzip can handle already compressed data i.e. index.html.gz and send it as-is.</P
><P
></P
><P
>The conclusion: You carefully have to make a decision which of the two modules makes more sense for you. If you have to
pay for every GB delivered and CPU-power does not matter, then mod_gzip is the choice for you. If response time matters
(delay between request and delivery), and your bandwidth is cheap or unlimited, mod_gunzip matches your needs better.</P
><P
></P
><P
>A good page that helps you to make this decision is Martin Kiff's document about mod_gunzip
<A
HREF="http://www.innerjoin.org/apache-compression/howto.html"
TARGET="_top"
>http://www.innerjoin.org/apache-compression/howto.html</A
></P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN601"
></A
>5.1. mod_gzip</H2
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN603"
></A
>5.1.1. Download the source</H3
><P
>Origin-Site: <A
HREF="http://prdownloads.sourceforge.net/mod-gzip/mod_gzip-1.3.26.1a.tgz?download"
TARGET="_top"
>http://prdownloads.sourceforge.net/mod-gzip/mod_gzip-1.3.26.1a.tgz?download</A
></P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN607"
></A
>5.1.2. Building and installing</H3
><P
>To successfully compile mod_gzip you need to edit the <TT
CLASS="FILENAME"
>Makefile</TT
> and provide the correct path to
<B
CLASS="COMMAND"
>apxs</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>make
make install</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN613"
></A
>5.1.3. Sample configuration</H3
><P
>Put the following in your <TT
CLASS="FILENAME"
>/usr/local/apache/conf/httpd.conf</TT
>:</P
><DIV
CLASS="EXAMPLE"
><A
NAME="AEN617"
></A
><P
><B
>Example 5. /usr/local/apache/conf/httpd.conf</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>mod_gzip_on Yes
mod_gzip_can_negotiate Yes
mod_gzip_dechunk Yes
mod_gzip_minimum_file_size 600
mod_gzip_maximum_file_size 0
mod_gzip_maximum_inmem_size 100000
mod_gzip_keep_workfiles No
mod_gzip_temp_dir /usr/local/apache/gzip
mod_gzip_item_include file \.html$
mod_gzip_item_include file \.txt$
mod_gzip_item_include file \.jsp$
mod_gzip_item_include file \.php$
mod_gzip_item_include file \.pl$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-httpd-php
mod_gzip_item_include mime ^httpd/unix-directory$
mod_gzip_item_include handler ^perl-script$
mod_gzip_item_include handler ^server-status$
mod_gzip_item_include handler ^server-info$
mod_gzip_item_exclude file \.css$
mod_gzip_item_exclude file \.js$
mod_gzip_item_exclude mime ^image/.*</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>You may whish to log the result of the compression to your accesslog. This can be done
by changing the LogFormat directive in <TT
CLASS="FILENAME"
>/usr/local/apache/conf/httpd.conf</TT
>
<TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>LogFormat "%h %l %u %t \"%r\" %&#62;s %b \"%{Referer}i\" \"%{User-Agent}i\" mod_gzip: %{mod_gzip_compression_ratio}npct." combined</PRE
></FONT
></TD
></TR
></TABLE
>&#13;</P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN623"
></A
>5.2. mod_gunzip</H2
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN625"
></A
>5.2.1. Download the source</H3
><P
>Origin-Site: <A
HREF="http://www.oldach.net/mod_gunzip.tar.gz"
TARGET="_top"
>http://www.oldach.net/mod_gunzip.tar.gz</A
></P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN629"
></A
>5.2.2. Building and installing</H3
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>tar -xvzf mod_gunzip.tar.gz
cd mod_gunzip-2
/usr/local/apache/bin/apxs -i -a -c -lz mod_gunzip.c</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="AEN632"
></A
>5.2.3. Sample configuration</H3
><P
>Put the following in your <TT
CLASS="FILENAME"
>/usr/local/apache/conf/httpd.conf</TT
>:</P
><DIV
CLASS="EXAMPLE"
><A
NAME="AEN636"
></A
><P
><B
>Example 6. /usr/local/apache/conf/httpd.conf</B
></P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>AddType text/html .htmz
AddHandler send-gunzipped .htmz</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><P
>Now you can gzip your html files and rename them to i.e:</P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>gzip index.html
mv index.html.gz index.htmz</PRE
></FONT
></TD
></TR
></TABLE
><P
>Of course you have to change all links to htmz, i.e. &#60;a href="page.htmz"&#62;Some page&#60;/a&#62;</P
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="modules.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="php.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Additional modules</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>mod_php and its prerequisites</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>