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

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.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

 原文:http://blog.linuxeye.com/349.html

你可能感兴趣的:(apache)