blob: 2c49161b65a02afaa8124083fd5f95cd38d4f673 [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
<?xml-stylesheet type="text/xsl" href="../style/manual.ja.xsl"?>
<!-- English Revision: 420990:1728020 (outdated) -->
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<modulesynopsis metafile="mod_deflate.xml.meta">
<name>mod_deflate</name>
<description>クライアントへ送られる前にコンテンツを圧縮する</description>
<status>Extension</status>
<sourcefile>mod_deflate.c</sourcefile>
<identifier>deflate_module</identifier>
<summary>
<p><module>mod_deflate</module> モジュールは <code>DEFLATE</code>
出力フィルタを提供します。これはサーバからの出力を、ネットワークを
通してクライアントに送る前に圧縮することを可能にします。</p>
</summary>
<seealso><a href="../filter.html">Filters</a></seealso>
<section id="recommended"><title>サンプル設定</title>
<p>下にせっかちな人向けの簡単な設定例を示します。</p>
<example><title>数タイプのみ圧縮する</title>
AddOutputFilterByType DEFLATE text/html text/plain text/xml
</example>
<p>以下の設定はコンテンツをより圧縮しますが、ずっと複雑な設定になります。
設定の隅々までよく理解しないで使わないでください。</p>
<example><title>画像以外全て圧縮する</title>
&lt;Location /&gt;<br />
<indent>
# Insert filter<br />
SetOutputFilter DEFLATE<br />
<br />
# Netscape 4.x has some problems...<br />
BrowserMatch ^Mozilla/4 gzip-only-text/html<br />
<br />
# Netscape 4.06-4.08 have some more problems<br />
BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
<br />
# MSIE masquerades as Netscape, but it is fine<br />
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html<br />
<br />
# Don't compress images<br />
SetEnvIfNoCase Request_URI \<br />
<indent>
\.(?:gif|jpe?g|png)$ no-gzip dont-vary<br />
</indent>
<br />
# Make sure proxies don't deliver the wrong content<br />
Header append Vary User-Agent env=!dont-vary<br />
</indent>
&lt;/Location&gt;
</example>
</section>
<section id="enable"><title>圧縮を有効にする</title>
<section id="output"><title>Output Compression</title>
<p>圧縮機能は <code>DEFLATE</code> <a href="../filter.html">フィルタ</a>
により実装されています。以下のディレクティブはそのディレクティブのある
コンテナ中のドキュメントを圧縮するようにします:</p>
<example>
SetOutputFilter DEFLATE
</example>
<p>よく使われているブラウザでは、すべてのコンテンツに対する
圧縮を扱えるわけではありません。ですから、<code>gzip-only-text/html</code>
ノートを <code>1</code> にして、html ファイルに対してのみ
圧縮が働くようにした方がよいかもしれません (以下参照)
この値を <em><code>1</code> 以外の値</em>に設定した場合は無視されます。</p>
<p>通常、特定のMIMEタイプについてのみ圧縮したいのであれば、
<directive module="core">AddOutputFilterByType</directive>
ディレクティブを使用します。次に Apache のドキュメントの html
ファイルのみの圧縮を有効にする例を示します。</p>
<example>
&lt;Directory "/your-server-root/manual"&gt;<br />
<indent>
AddOutputFilterByType DEFLATE text/html<br />
</indent>
&lt;/Directory&gt;
</example>
<p>全てのファイルタイプでの圧縮に問題を抱えているブラウザに対しては、
<directive module="mod_setenvif">BrowserMatch</directive>
ディレクティブを使用して、特定のブラウザに <code>no-gzip</code>
ノートをセットし、圧縮が行なわれないようにします。
<code>no-gzip</code><code>gzip-only-text/html</code>
を組み合わせることで上手く対処できます。
この場合、前者が後者をオーバーライドします。
上記の<a href="#recommended">設定例</a>の抜粋を
次に示しますのでご覧下さい。</p>
<example>
BrowserMatch ^Mozilla/4 gzip-only-text/html<br />
BrowserMatch ^Mozilla/4\.0[678] no-gzip<br />
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</example>
<p>まず始めに <code>User-Agent</code> 文字列から Netscape Navigator
4.x であるかどうかを調べます。これらのバージョンでは、
<code>text/html</code> 以外のタイプの圧縮を扱うことができません。
4.06, 4.07, 4.08 は html ファイルの伸張にも問題を抱えています。
ですからこれらに対しては、完全に deflate フィルタをオフにします。</p>
<p>3 番目の <directive module="mod_setenvif">BrowserMatch</directive>
ディレクティブで、推測したユーザーエージェントを修正します。
なぜなら Microsoft Internet Explorer も "Mozilla/4" と特定されますが、
これらは実際には圧縮を扱うことができるからです。
<code>User-Agent</code> ヘッダを "MSIE"
(<code>\b</code> は「単語の境界」を意味します) の追加文字で検査して、
これ以前に設定した制限を再び解除します。</p>
<note><title></title>
<code>DEFLATE</code> フィルタは必ず、PHP や SSI といった RESOURCE
フィルタの後になります。
DEFLATE フィルタは内部的なサブリクエストを関知しません。
</note>
<note><title></title>
<directive module="core">SetEnv</directive> で設定される
<code>force-gzip</code> 環境変数がありますが、これは
ブラウザの accept-encoding 設定を無視し、圧縮した出力をします。
</note>
</section>
<section id="inflate"><title>出力の伸長</title>
<p><module>mod_deflate</module> モジュールは、gzip 圧縮されたレスポンス
本文を inflate/uncompress するフィルタも提供しています。
この機能を有効にするには、<directive module="core">SetOutputFilter</directive>
<directive module="mod_mime">AddOutputFilter</directive> を使って、
<code>INFLATE</code> フィルタを出力フィルタチェインに挿入します。
例えば次のようにします。</p>
<example>
&lt;Location /dav-area&gt;<br />
<indent>
ProxyPass http://example.com/<br />
SetOutputFilter INFLATE<br />
</indent>
&lt;/Location&gt;
</example>
<p>この例では、example.com からの gzip 圧縮された出力を伸長し、
その他のフィルタがさらにその出力を処理できるようにします。
</p>
</section>
<section id="input"><title>入力の伸張</title>
<p><module>mod_deflate</module> モジュールは、gzip
で圧縮されたリクエスト本体を伸張するフィルタも提供しています。
この機能を有効にするには、<directive module="core">SetInputFilter</directive>
<directive module="mod_mime">AddInputFilter</directive> を使用して、
<code>DEFLATE</code> フィルタを入力フィルタチェインに組み込みます。
例えば次のようになります。</p>
<example>
&lt;Location /dav-area&gt;<br />
<indent>
SetInputFilter DEFLATE<br />
</indent>
&lt;/Location&gt;
</example>
<p>この設定であれば、<code>Content-Encoding: gzip</code>
ヘッダを含むリクエストが来ると、本体は自動的に伸張されます。
gzip リクエスト本体を送信するブラウザはあまりありません。
しかし、例えば <a href="http://www.webdav.org">WebDAV</a>
クライアントの幾つかなど、特別なアプリケーションでリクエストの
圧縮を実際にサポートしているものもあります。</p>
<note type="warning"><title>Content-Length に関する注意</title>
<p>リクエスト本体それ自体を評価する場合は、<em><code>Content-Length</code>
ヘッダを信用しないでください</em>。Content-Length ヘッダは、
クライアントから送信されるデータの長さを反映しているのであって、
伸張されたデータストリームの<em>バイトカウントではありません</em></p>
</note>
</section>
</section>
<section id="proxies"><title>Proxy サーバでの扱い</title>
<p><module>mod_deflate</module> モジュールは <code>Vary: Accept-Encoding</code>
HTTP 応答ヘッダを送信して、適切な <code>Accept-Encoding</code>
リクエストヘッダを送信するクライアントに対してのみ、
プロクシサーバがキャッシュした応答を送信するように注意を喚起します。
このようにして、圧縮を扱うことのできないクライアントに
圧縮された内容が送られることのないようにします。</p>
<p>もし特別に何かに依存して除外したい場合、例えば <code>User-Agent</code>
ヘッダなどに依存している場合、手動で <code>Vary</code> ヘッダを設定して、
追加の制限についてプロクシサーバに注意を行なう必要があります。
例えば <code>User-Agent</code> に依存して <code>DEFLATE</code>
を追加する典型的な設定では、次のように追加することになります。</p>
<example>
Header append Vary User-Agent
</example>
<p>リクエストヘッダ以外の情報 (<em>例えば</em> HTTP バージョン)
に依存して圧縮するかどうか決める場合、
<code>Vary</code> ヘッダを <code>*</code> に設定する必要があります。
このようにすると、仕様に準拠したプロクシはキャッシュを全く行なわなくなります。</p>
<example><title></title>
Header set Vary *
</example>
</section>
<directivesynopsis>
<name>DeflateFilterNote</name>
<description>ロギング用に圧縮比をメモに追加</description>
<syntax>DeflateFilterNote [<var>type</var>] <var>notename</var></syntax>
<contextlist><context>server config</context>
<context>virtual host</context></contextlist>
<compatibility><var>type</var> is available since Apache 2.0.45</compatibility>
<usage>
<p><directive>DeflateFilterNote</directive> ディレクティブは
圧縮比に関するメモがリクエストに付加されることを指定します。
メモ (note) の名前はディレクティブに指定された値です。
メモは<a href="../logs.html#accesslog">アクセスログ</a>
値を記録し、統計を取る目的にも使えます。</p>
<example><title></title>
DeflateFilterNote ratio<br />
<br />
LogFormat '"%r" %b (%{ratio}n) "%{User-agent}i"' deflate<br />
CustomLog logs/deflate_log deflate
</example>
<p>ログからもっと精密な値を抽出したい場合は、<var>type</var>
引数を使用して、データタイプをログのメモとして残すように指定できます。
<var>type</var> は次のうちの一つです。</p>
<dl>
<dt><code>Input</code></dt>
<dd>フィルタの入力ストリームのバイトカウントをメモに保存する。</dd>
<dt><code>Output</code></dt>
<dd>フィルタの出力ストリームのバイトカウントをメモに保存する。</dd>
<dt><code>Ratio</code></dt>
<dd>圧縮率 (<code>出力 / 入力 * 100</code>) をメモに保存する。
<var>type</var> 引数を省略した場合は、これがデフォルトとなります。</dd>
</dl>
<p>まとめると、次のようにログを取ることになるでしょう。</p>
<example><title>精密なログ採取</title>
DeflateFilterNote Input instream<br />
DeflateFilterNote Output outstream<br />
DeflateFilterNote Ratio ratio<br />
<br />
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate<br />
CustomLog logs/deflate_log deflate
</example>
</usage>
<seealso><module>mod_log_config</module></seealso>
</directivesynopsis>
<directivesynopsis>
<name>DeflateBufferSize</name>
<description>zlib が一度に圧縮する塊の大きさ</description>
<syntax>DeflateBufferSize <var>value</var></syntax>
<default>DeflateBufferSize 8096</default>
<contextlist><context>server config</context>
<context>virtual host</context></contextlist>
<usage>
<p><directive>DeflateBufferSize</directive> ディレクティブは
zlib が一度に圧縮する塊の大きさをバイト単位で指定します。</p>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>DeflateWindowSize</name>
<description>Zlib の圧縮用ウィンドウの大きさ</description>
<syntax>DeflateWindowSize <var>value</var></syntax>
<default>DeflateWindowSize 15</default>
<contextlist><context>server config</context>
<context>virtual host</context></contextlist>
<usage>
<p><directive>DeflateWindowSize</directive> ディレクティブは
zlib の圧縮用ウィンドウ (訳注: zlib で使用される履歴バッファ)
の大きさを指定します (1 から 15 の間の値)。
一般的に大きなウィンドウサイズを使用すると圧縮率が向上します。
(訳注: 2 を底とする対数の値になります。
8 から 15 にするのが良いでしょう。)</p>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>DeflateMemLevel</name>
<description>zlib が圧縮に使うメモリのレベルを指定</description>
<syntax>DeflateMemLevel <var>value</var></syntax>
<default>DeflateMemLevel 9</default>
<contextlist><context>server config</context>
<context>virtual host</context></contextlist>
<usage>
<p><directive>DeflateMemLevel</directive> ディレクティブは
zlib が圧縮に使うメモリのレベルを設定します (1 から 9 の間の値)。
(訳注: 2 を底とする対数の値になります。
8 程度が良いでしょう。)</p>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>DeflateCompressionLevel</name>
<description>出力に対して行なう圧縮の程度</description>
<syntax>DeflateCompressionLevel <var>value</var></syntax>
<default>Zlib のデフォルト</default>
<contextlist><context>server config</context><context>virtual host</context>
</contextlist>
<compatibility>This directive is available since Apache 2.0.45</compatibility>
<usage>
<p><directive>DeflateCompressionLevel</directive> ディレクティブは
圧縮の程度を設定します。大きな値では、より圧縮が行なわれますが、
CPU 資源を消費します。</p>
<p>値は 1 (低圧縮) から 9 (高圧縮) です。</p>
</usage>
</directivesynopsis>
</modulesynopsis>