LoginSignup
4
4

More than 5 years have passed since last update.

Apache filter_moduleでgzip圧縮(AmazonLinux)

Last updated at Posted at 2014-02-12

概要

  • filterモジュール使ったconfの書き方と、動作確認をまとめておく
    • AddOutputFilterByTypeディレクティブ使った方法はApache2.2で非推奨
  • 圧縮レベルは5
  • 対象はtext/*のやつ全部
  • ログは効果確認できたら出さないようにする

conf

httpd.conf
# deflate_module と filter_moduleをアンコメント
LoadModule deflate_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so
app.conf
<IfModule mod_deflate.c>
  DeflateCompressionLevel 5
  <Location />
    FilterDeclare  Comp CONTENT_SET
    FilterProvider Comp DEFLATE req=Accept-Encoding $gzip
    FilterProvider Comp DEFLATE resp=Content-Type /^text/
    FilterChain Comp
  </Location>

  # ログは重くなるので効果確認できたら消す
  DeflateFilterNote Input instream
  DeflateFilterNote Output outstream
  DeflateFilterNote Ratio ratio
  LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
  CustomLog logs/deflate_log deflate
</IfModule>

効果確認

  • curlで確認
curl -H "Accept-Encoding: gzip" -H "Pragma: no-cache" "http://localhost/index.css"
sudo tail -1 /etc/httpd/logs/deflate_log
"GET /index.css HTTP/1.1" 3877/16699 (23%)

参考

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4