转自
http://www.tecmint.com/install-mod_pagespeed-to-boost-apache-nginx-performance/
This is our on going series on Apache optimization and performance tuning, here we are introducing a new Google‘s product called mod_pagespeed module for Apache or Nginx that makes the web site load much faster than ever.
I have personally tested this module on our Live (tecmint.com) server and results are amazing, now the site loads much faster than before. I recommend you all to install it and see the results.
Don’t Miss: 5 Tips to Boost the Performance of Your Apache Web Server
In this article we will show you how to install and configure Google‘s mod_pagespeed module for Apacheand Nginx web servers in RHEL/CentOS/Fedora and Debian/Ubuntu systems using official binary packages, so that your system will get regular updates automatically and stays up to date.
What Is Mod_PageSpeed
mod_pagespeed is an open source module for Apache and Nginx web server that automatically optimize Web Pages to improve better performance while serving web pages using HTTP Server.
It has several filters that automatically optimize files like HTML, CSS, JavaScript, JPEG, PNG and other resources.
mod_pagespeed is developed on PageSpeed Optimization Libraries, deployed over 100K+ websites, and provided by most popular CDN and Hosting providers such as GoDaddy, EdgeCast, DreamHost and few to name.
It offers more than 40+ optimization filters, which includes:
- Image optimization, compression, and resizing
- CSS & JavaScript concatenation, minification, and inlining
- Cache extension, domain sharding and rewriting
- Deferred loading of JS and image resources
- and many others…
Currently mod_pagespeed module supported Linux platforms are RHEL/CentOS/Fedora and Debian/Ubuntu for 32 bit and 64 bit distributions.
Installing Mod_Pagespeed Module in Linux
As I discussed above that we are using Google‘s official binary packages to install it for future updates, so let’s go ahead and install it on your systems based on your OS architecture.
On RHEL/CentOS and Fedora
On Debian and Ubuntu
Installing mod_pagespeed from binary packages will add a Google’s official repository to your system, so that you can update the mod_pagespeed automatically using package manager called yum or apt.
What Mode_Pagespeed is Installed
Let’s see what packages mod_pagespeed installed on the system:
- It will install two modules, mod_pagespeed.so for Apache 2.2 and mod_pagespeed_ap24.so for Apache 2.4.
- It will install two main configuration files: pagespeed.conf and pagespeed_libraries.conf (for Debian pagespeed.load). If you change one of these configuration files, you will no longer receive future updates automatically.
- A standalone JavaScript minifier pagespeed_js_minify used to minify JS and create metadata for library canonicalization.
About Mod_Pagespeed Configuration and Directories
The module enables following configuration files and directories itself automatically during installation.
- /etc/cron.daily/mod-pagespeed : mod_pagespeed cron script for checking and installing latest updates.
- /etc/httpd/conf.d/pagespeed.conf : The main configuration file for Apache in RPM based distributions.
- /etc/apache2/mods-enabled/pagespeed.conf : The main configuration file for Apache2 in DEB based distributions.
- pagespeed_libraries.conf : The default set of libraries for Apache, loads at Apache startup.
- /usr/lib{lib64}/httpd/modules/mod_pagespeed.so : mod_pagespeed module for Apache.
- /var/cache/mod_pagespeed : File caching directory for web sites.
Important: In Nginx the configuration files of mod_pagespeed typically found under /usr/local/nginx/conf/directory.
Configuring Mod_Pagespeed Module
In Apache, mod_pagespeed automatically Turn On when installed, while in Nginx you need to place following lines to your nginx.conf file and in every server block where PageSpeed is enabled:
Finally, don’t forget to restart your Apache or Nginx server to start mod_pagespeed working properly.
Step 4: Verifying Mod_Pagespeed Module
To verify mod_pagespeed module, we will use curl command to test in on domain or IP as shown:
Apache
Nginx
If you don’t see an X-Mod-Pagespeed header, that means mod_pagespeed isn’t actually installed.
Step 5: Turning the Module On and Off
If you don’t want to use mod_pagespeed completely, you can Turn Off by inserting the following line to pagespeed.conf file at the top.
Similarly, to Turn On module, insert the following line to pagespeed.conf file at the top.
As I said above after installing mod_pagespeed our website loads 40%-50% faster. We would really like to know about your website speed after installing it on your systems via comments.
For more details about configuration, you can check out the official mod_pagespeed page at https://developers.google.com/speed/pagespeed/module/.