IT技术互动交流平台

apache的gzip压缩和缓存优化记录

作者:糊涂不糊涂  发布日期:2011-09-08 16:13:09

给一个朋友的站点做的gzip压缩和缓存的优化配置,这里记录一下

编译mod_deflate.so/mod_headers.so/mod_expires.so模块
/www/wdlinux/apache/bin/apxs -i -c -a /source/lanmp/httpd-2.2.17/modules/filters/mod_deflate.c
/www/wdlinux/apache/bin/apxs -i -c -a /source/lanmp/httpd-2.2.17/modules/metadata/mod_headers.c
/www/wdlinux/apache/bin/apxs -i -c -a /source/lanmp/httpd-2.2.17/modules/metadata/mod_expires.c


httpd.conf加入:

#---------mod_deflate module confiugration--------------------
SetOutputFilter DEFLATE
DeflateCompressionLevel 6

BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
#Explicit exclusion of files.
SetEnvIfNoCase Request_URI \.(?:gif|jpg|cab|jpe?g|exe|bmp|mp3|rar|zip|swf|png)$ no-gzip dont-vary
#Cache server support.
Header append Vary User-Agent env=!dont-vary
#logs.
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog logs/deflate_log deflate
#-------------------------------------------------------------

网站根目录的.htaccess文件中加入:

ExpiresActive on
ExpiresByType text/html "access 2 day"
ExpiresByType text/css "access 2 day"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/plain "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresDefault "access 2 days"

Tag标签: apache   gzip   压缩   缓存优化  
  • 专题推荐

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规