The Apache Accelerated Module Mod_pagespeed Installation use detailed introduction _linux

Source: Internet
Author: User

I. Introduction to Mod_pagespeed
Mod_pagespeed is a module for Apache httpd, open source code released by Google that automates optimization, including optimizing caching, reducing communication between client servers, reducing load, and so on. Deploy mod_pagespeed do not need to modify any program, after installation to restart Apache, all front-end problems automatically optimized. CDN Service Provider Cotendo has been deployed on its CDN server mod_pagespeed to speed up customer site access, picture file size by automatic compression can be reduced by 20%-30%, page load time can be shortened by 50%. GoDaddy also announced that it will be widely deployed on its client Web server mod_pagespeed.
Mod_pagespeed Project homepage: https://developers.google.com/speed/pagespeed/
second, the function of Mod_pagespeed
1.Optimize Caching Optimized cache
Extend Cache Extension Caching
Outline CSS
Outline JavaScript
2.Minimize Round trips times minimizes round-trip time
Combine CSS Merge CSS
Inline CSS Inline CSS
Inline JavaScript inline JavaScript
3.Minimize Payload size Minimize payload size
Collapse Whitespace compressed blank
Combine Heads Merge Header information
Elide Attributes omitted attribute
Minify JavaScript shrinks JavaScript
Optimize Images Optimized picture
Remove Comments Delete Comment
Remove quotes Delete Reference
Rewrite CSS Rewrite CSS
Move CSS to head load CSS into head
ADD Head
ADD instrumentation
Iii. The basic principles of Mod_pagespeed
Mod_pagespeed improves page latency and bandwidth efficiency by modifying the resources on the requested Web page. When Apache HTTP server is serving Web site resources, each of the optimizations in Mod_pagespeed module is placed in a customizable filter. Some filters directly modify the HTML content, while others adjust the css,javascript and pictures referenced in the page to create a more optimized page.
iv. installation of Mod_pagespeed
Mod_pagespeed currently supports Apache and Nginx. The simple installation method in Apache is as follows. After the installation is complete, it will create a new installation source in Yum and then update it via Yum update.
Install under Centos/fedora:

Copy Code code as follows:
#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

Install under Debina/ubuntu:

Copy Code code as follows:

#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

Reboot httpd:

Copy Code code as follows:
Services httpd Restart

To see if Pagespeed is loaded:
Copy Code code as follows:
Httpd-m|grep Pagespeed

V. Configuration of Mod_pagespeed
Generally after the successful installation, do not need any configuration can be used normally, of course, if you have higher requirements, you can refer to the following content.

1. Create a configuration file

Copy Code code as follows:
Vi/usr/local/apache/conf/pagespeed.conf #新建配置文件, please revise according to your own needs
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>

2. Using the configuration file
Copy Code code as follows:

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 #重启apache

Vi. Advanced Applications of Mod_pagespeed
Mod_pagespeed has a series of default optimization options (filter) that automatically opens after the installation is complete, and you can see the effect by restarting Apache only.

The basics of optimization are already included, such as compressing CSS and JavaScript, extending the expiration of resources, rewriting pictures, and so on, if you want to further optimize, you can consider a few options:
1.remove_comments: Deletes comments from the source file. In most cases, annotations are not visible to end users and will not affect browsing after they are deleted. and mod_pagespeed can recognize IE's conditional annotation without moving it.
2.collapse_whitespace: Deletes the white space character in the source file, ditto, does not affect browsing.
3.insert_dns_prefetch: to guide the browser in advance DNS resolution, if your blog refers to other sites in the picture, such as the blog using Google Cloud storage as a bed, add this option, you can allow the browser to resolve in advance Cloud Storage DNS, which speeds up the download of pictures.
Adding options requires modifying the/etc/httpd/conf.d/pagespeed.conf file and adding the following code. Note that you will still need to restart Apache after the modification.

Copy Code code as follows:
Modpagespeeddisablefilters Remove_comments,collapse_whitespace

In addition, if your site has HTTPS enabled, you need to make special settings for HTTPS because the communication is encrypted in HTTPS, and Mod_pagespeed is not aware of it. setting is also a word:
Copy Code code as follows:
Modpagespeedmaporigindomain http://jb51.net https://jb51.net

All done, refresh the page to see the effect of it.
Vii. Temporarily disable the Pagespeed component
When you debug a Web site, you sometimes need to disable the caching component so that you can see the latest changes. The page speed component can become a hindrance at this time, and it will not be able to detect changes in the original file in time for the cache to be cached again.
Of course, disabling it is also easy, even SSH is not used. Just add parameter modpagespeed=off to the URL you want to debug, such as this:
Copy Code code as follows:
Http://jb51.net/?ModPagespeed=off

You can access pages that have not been optimized by page speed, and if you look at the source files carefully, you can find some differences.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.