VPS Apache gzip リソースを圧縮 (+キャッシュ設定)

参考サイト:https://everyday-growth.com/?p=1946

有効か確認

# cat /etc/httpd/conf.modules.d/00-base.conf
...
// 下記ががあれば有効済み
LoadModule deflate_module modules/mod_deflate.so
...

圧縮設定

# vi /etc/httpd/conf/httpd.conf
<IfModule mod_deflate.c>
     SetOutputFilter DEFLATE
     # gifやjpgなど圧縮済みコンテンツは再圧縮しない
     SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|ico)$ no-gzip dont-vary
     SetEnvIfNoCase Request_URI _\.utxt$ no-gzip
     # htmlやcssなど圧縮
     AddOutputFilterByType DEFLATE text/plain
     AddOutputFilterByType DEFLATE text/html
     AddOutputFilterByType DEFLATE text/xml
     AddOutputFilterByType DEFLATE text/css
     AddOutputFilterByType DEFLATE application/xhtml+xml
     AddOutputFilterByType DEFLATE application/xml
     AddOutputFilterByType DEFLATE application/rss+xml
     AddOutputFilterByType DEFLATE application/atom_xml
     AddOutputFilterByType DEFLATE application/x-javascript
     AddOutputFilterByType DEFLATE application/x-httpd-php
</IfModule>
# service httpd restart

キャッシュ設定

# キャッシュの期間を設定
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 30 minutes"
ExpiresByType image/png "access plus 7 days"
ExpiresByType image/jpg "access plus 7 days"
ExpiresByType image/jpeg "access plus 7 days"
ExpiresByType image/svg+xml "access plus 7 days"
ExpiresByType image/gif "access plus 7 days"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType text/html "access plus 10 seconds"
ExpiresByType text/css "access plus 7 days"
ExpiresByType text/js "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
</ifModule>
PAGE TOP