Apache下安装配置mod_pagespeed模块,轻松完成网站提速

  • A+
所属分类:Linux

mod_pagespeed是一个开源的Apache module,它由谷歌开发,通过优化你的网页来减少响应延迟和带宽占用。作用参考ngx_pagespeed功能://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.rpm
else
    wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm
fi

安装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:   Aug  1 2013 17: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/"
    ModPagespeedFileCacheInodeLimit        500000
    ModPagespeedAvoidRenamingIntrospectiveJavascript on
    ModPagespeedEnableFilters collapse_whitespace
    <Location /mod_pagespeed_beacon>
          SetHandler mod_pagespeed_beacon
    </Location>
    <Location /mod_pagespeed_statistics>
        Order allow,deny
        Allow from localhost
        Allow from 127.0.0.1
        SetHandler mod_pagespeed_statistics
    </Location>
    ModPagespeedMessageBufferSize 100000

    <Location /mod_pagespeed_message>
        Allow from localhost
        Allow from 127.0.0.1
        SetHandler 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

Wed Aug  7 18:36:11 CST 2013

avatar

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  1   博主  1

    • avatar LeeJon 1

      无论是mod_pagespeed.so还是mod_pagespeed_ap24.so都提示httpd: Syntax error on line 511 of /usr/local/apache/conf/httpd.conf: Syntax error on line 1 of /usr/local/apache/conf/pagespeed.conf: Cannot load /usr/local/apache/modules/mod_pagespeed.so into server: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14′ not found (required by /usr/local/apache/modules/mod_pagespeed.so)
      使用的是debian7 64,这个咋办? :shock:

        • avatar yeho Admin

          @LeeJon 已经放弃,建议不要安装,bug不少,不稳定。还不如直接加cdn