日志标签:apacheapache

Apache安装mod_pagespeed模块加速网站

分类:linux日期:2014-01-05 - 20:46:23评论:1条作者:老谢

mod_pagespeed

该模块可以有效将网页加载速度提高50%+,Google这款加速模块简单的解决了许多复情况的问题:

  • 加速模块可以自行对网络传输的html字节优化及对图象,css进入压缩优化传输;
  • js的自动压缩;
  • 智能缓存是一大亮点,它可以自动智能缓存,加速下载。
  • 直接开启模块即可,不需要过多设置;

懒得折腾varnish、nginx这些前端了,因为好几个网站改配置文件什么的太烦,好吧,我到底是多懒,既然已经懒成这样,apache本身能不能提供一个压缩或缓存呢?搜了一圈以后,决定安装mod_pagespeed模块,这个模块由google提供,上面已经简单的进行了描述,下面贴出配置过程:

配置mod_pagespeed

Tips:mod_pagespeed 需要 Apache 加载 mod_deflate(一个将 web内容gzip压缩后传输的模块)。

32位请执行:wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.rpm
64位请执行:wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
rpm2cpio ./mod-pagespeed-stable_current_i386.rpm | cpio -idmv
./etc/cron.daily/mod-pagespeed
./etc/httpd/conf.d/pagespeed.conf
./etc/httpd/conf.d/pagespeed_libraries.conf
./usr/bin/pagespeed_js_minify
./usr/lib/httpd/modules/mod_pagespeed.so
./usr/lib/httpd/modules/mod_pagespeed_ap24.so
./var/cache/mod_pagespeed
./var/log/pagespeed
27020 blocks
cp ./usr/lib/httpd/modules/mod_pagespeed.so /usr/local/apache/modules/ #apache版本>=2.4.2,用pagespeed_ap24.so
chmod 0755 /usr/local/apache/modules/mod_pagespeed.so
vim /usr/local/apache/conf/pagespeed.conf #新建配置文件,请根据自己需求修改
LoadModule pagespeed_module /usr/local/apache/modules/mod_pagespeed.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