
私は http.conf ファイルに次の内容を追加しました:
# mod_deflate configuration
<IfModule mod_deflate.c>
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
# Level of compression (Highest 9 - Lowest 1)
DeflateCompressionLevel 9
# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
<IfModule mod_headers.c>
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
私のコンテンツは gzip タイプの Content-Encoding で返されませんが、304 が頻繁に返され、Etag に +gzip サフィックスが追加されます。mod_deflate は実際に機能しているのでしょうか? (初心者っぽくてすみません)
答え1
ヘッダーは何を示していますか?「content-encoding: gzip」が返されない場合は、おそらく機能していません。次のようにテストできます。
curl -I -H 'Accept-Encoding: gzip,deflate' http://yoursite.com/somefile
答え2
Apacheのドキュメントタイプ別に出力フィルターを追加このディレクティブは Apache httpd 2.1 以降では非推奨であり、Apache が MIME タイプを判別できない場合には必ずしも正常に機能しないことを示します。
開始点として次のようなものを使用して圧縮を有効にし、その後、すべてのブラウザの調整と圧縮レベルを元に戻すことを推奨します。当然、httpd.conf を再確認して、mod_deflate.so も実際にロードされていることを確認する必要があります。
<Location />
SetOutputFilter DEFLATE
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|png|jpg|jpeg)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</Location>
確認するには、Michael Steinfeld が述べたように cURL を使用します。
答え3
評判が足りないのでコメントを追加できません。そのため、これを回答として書いています。
Michael Steinfeld による元の回答では、次のエラーが出力されていました (Windows コマンド プロンプト)
curl: (6) Could not resolve host: gzip,deflate'
コロンの後のスペースを削除することで解決しました。
curl -I -H 'Accept-Encoding:gzip,deflate' http://yoursite.com/somefile
答え4
とLogLevel
に設定するとdebug
、mod_deflateはデバッグメッセージをErrorLog
圧縮されているすべてのリソースはログに記録されます。mod_deflateがリアルタイムで動作しているかどうかは、
tail -f /path/to/error-log | grep deflate
例えば
[2015 年 4 月 22 日水曜日 05:37:49.742615] [deflate:debug] [pid 22627] mod_deflate.c(849): [client 127.0.0.1:55667] AH01384: Zlib: 10700 から 2637 まで圧縮されました: URL /web/js/common.js、リファラー:ローカルホスト