mod_pagespeed是一个开源的Apache module,它由谷歌开发,通过优化你的网页来减少响应延迟和带宽占用。作用参考ngx_pagespeed功能:http://blog.linuxeye.com/318.html
mod_pagespeed 需要 Apache 加载 mod_deflate(一个将 web内容gzip压缩后传输的模块)。
本文是基于LAMP环境,LAMP脚本参考:《LAMP最新源码安装脚本》
下载解压mod_pagespeed模块
cd /root/lamp/source/if[`getconf WORD_BIT`='32']&&[`getconf LONG_BIT`='64'];then wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpmelse wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpmfi
安装mod_pagespeed模块
mkdir mod_pagespeed rpm2cpio ../mod-pagespeed-stable_current_x86_64.rpm | cpio -idmv # /usr/local/apache/bin/apachectl -v #查看apache版本Server version:Apache/2.4.6(Unix)Server built:Aug1201317:07:51 cp ./usr/lib64/httpd/modules/mod_pagespeed_ap24.so /usr/local/apache/modules/#apache版本>=2.4.2,用pagespeed_ap24.so chmod 755/usr/local/apache/modules/mod_pagespeed_ap24.so
修改配置文件
vi /usr/local/apache/conf/pagespeed.conf #新建配置文件,请根据自己需求修改LoadModule pagespeed_module /usr/local/apache/modules/mod_pagespeed_ap24.so <IfModule pagespeed_module>ModPagespeed on ModPagespeedInheritVHostConfig on AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html ModPagespeedFileCachePath"/var/cache/mod_pagespeed/"ModPagespeedFileCacheInodeLimit500000ModPagespeedAvoidRenamingIntrospectiveJavascript on ModPagespeedEnableFilters collapse_whitespace <Location/mod_pagespeed_beacon>SetHandler mod_pagespeed_beacon </Location><Location/mod_pagespeed_statistics>Order allow,deny Allowfrom localhost Allowfrom127.0.0.1SetHandler mod_pagespeed_statistics </Location>ModPagespeedMessageBufferSize100000<Location/mod_pagespeed_message>Allowfrom localhost Allowfrom127.0.0.1SetHandler mod_pagespeed_message </Location></IfModule>
mkdir -p /var/mod_pagespeed/ chown -R www.www /var/mod_pagespeed/ echo 'Include conf/pagespeed.conf'>>/usr/local/apache/conf/httpd.conf /usr/local/apache/bin/apachectl -t Syntax OK service httpd restart
模块参数参考:https://developers.google.com/speed/pagespeed/module/config_filters