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

Linux2阅读模式

mod_pagespeed是一个开源的Apache module,它由谷歌开发,通过优化你的网页来减少响应延迟和带宽占用。作用参考ngx_pagespeed功能://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

 
  • 本文由 yeho 发表于 2013-08-07
  • 转载请务必保留本文链接:https://linuxeye.com/349.html
CentOS6.6下安装Redmine2.6(整合Apache2.4) Linux

CentOS6.6下安装Redmine2.6(整合Apache2.4)

Redmine是一个开源的、基于Web的项目管理和缺陷跟踪工具。它用日历和甘特图辅助项目及进度可视化显示。同时它又支持多项目管理。Redmine是一个自由开放源码软件解决方案,它提供集成的项目管理功能...
    • LeeJon
      LeeJon

      无论是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:

        • yeho
          yeho

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

      匿名

      发表评论

      匿名网友
      确定

      拖动滑块以完成验证