CentOS5默认apache是没有开启gzip压缩的,虽然默认读取了deflate_module,但是并没有在httpd.conf中配置,需要在httpd.conf中添加如下内容来配置deflate模块:
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript
设置Expires模块也能加速网页读取速度:
ExpiresActive On
ExpiresDefault A0
ExpiresByType text/html A2592000
ExpiresByType text/css A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/png A2592000
EXpiresByType application/x-shockwave-flash A2592000
EXpiresByType application/x-javascript A2592000
ExpiresByType video/x-flv A2592000
AddOutputFilterByType表示根据后面的MIME类型来压缩文件,这里对css,html,gif,jpeg,png,JavaScript等进行gzip压缩;
ExpiresByType是通过MIME类型来设置具体文件的缓存时间,A表示访问,A后面的数字表示访问后的缓存时间秒;
最后也可以关闭Etag来提升网页速度,配置文件中添加:
FileETag none