欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

Apache 安装配置mod_pagespeed加速模块

程序员文章站 2022-06-11 12:57:47
mod_pagespeed目前支持apache和nginx。apache中简单的安装方法如下。安装完成之后,它会在yum里新建一个安装源,之后通过yum update更新就...

mod_pagespeed目前支持apache和nginx。apache中简单的安装方法如下。安装完成之后,它会在yum里新建一个安装源,之后通过yum update更新就可以了

centos/fedora下安装

#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
yum install at
rpm -u mod-pagespeed-*.rpm

debina/ubuntu下安装

#32位
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_i386.deb
#64位
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.deb
dpkg -i mod-pagespeed-*.deb

重启httpd

service httpd restart

查看pagespeed是否加载:

httpd -m|grep pagespeed

配置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