# 32位
# wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_i386.rpm
# 64位
# https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-beta_current_x86_64.rpm
# mkdir mod-pagespeed
# cd mod-pagespeed
# rpm2cpio ../mod-pagespeed-beta_current_i386.rpm | cpio -idmv
# cp ./etc/httpd/conf.d/pagespeed.conf /usr/local/apache2/conf/
# cp ./usr/lib/httpd/modules/mod_pagespeed.so /usr/local/apache2/modules/
# chmod 755 /usr/local/apache2/modules/mod_pagespeed.so
# mkdir /var/mod_pagespeed/{cache,files} -p
# chown nobody:nobody /var/mod_pagespeed/*
之後用你習慣的編輯器打開 /usr/local/apache/conf/pagespeed.conf,將第一行修改為:
LoadModule pagespeed_module /usr/local/apache2/modules/mod_pagespeed.so
編輯 /usr/local/apache/conf/httpd.conf 在開頭的 Include 部分加入:
Include conf/pagespeed.conf
/usr/local/apache2/bin/apachectl -k restart
find / -name mod_deflate.c
cd /root/build/httpd-2.2.17/modules/filters/mod_deflate.c
/usr/local/apache2/bin/apxs -i -c -a mod_deflate.c
vi /usr/local/apache2/conf/httpd.conf LoadModule deflate_module modules/mod_deflate.so
<IfModule mod_deflate.c> DeflateCompressionLevel 7 AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php AddOutputFilter DEFLATE css js </IfModule>
LoadModule pagespeed_module /usr/local/apache2/modules/mod_pagespeed.so
<IfModule !mod_deflate.c>
LoadModule deflate_module /usr/local/apache2/modules/mod_deflate.so
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE css js
</IfModule>
<IfModule pagespeed_module>
ModPagespeed ON
AddOutputFilterByType MOD_PAGESPEED_OUTPUT_FILTER text/html
ModPagespeedFileCachePath "/var/mod_pagespeed/cache/"
ModPagespeedGeneratedFilePrefix "/var/mod_pagespeed/files/"
#保留頁面中原有格式,注釋的話會把包含的js引入到頁面中
ModPagespeedRewriteLevel PassThrough
ModPagespeedEnableFilters add_instrumentation
#不把圖片轉換成二進制格式
ModPagespeedDisableFilters rewrite_images
#壓縮JS
ModPagespeedEnableFilters rewrite_javascript
ModPagespeedEnableFilters collapse_whitespace,elide_attributes
<Location /mod_pagespeed_statistics>
Order allow,deny
Allow from localhost
SetHandler mod_pagespeed_statistics
</Location>
</IfModule>
請注意,mod_pagespeed 目前仍然處於 Beta 階段,據信它會大量執行寫操作於 /var/mod_pagespeed/ 以及 Apache 的日志文件,會消耗一定的資源。