Install Mod_Pagespeed to Speed Up Apache and Nginx

What Is Mod_PageSpeed

Mod_pagespeed is an open-source Apache HTTP Server or Nginx webservers module, which automatically applies chosen filters to pages and associated assets, such as stylesheets, JavaScript, and HTML files, as well as to images and website cache requirements. The largest advantage of this module is that it does not require modifications to existing content or workflow, meaning that all internal optimizations and changes to files are made on the server side, presenting modified files directly to the user. Each of 40+ filters corresponds to one of Google’s web performance best practices rules..
Optimization Libraries
  • Flatten CSS Imports
  • Canonicalize Javascript libraries
  • Defer Javascript
  • Inline Javascript
  • Deduplicate Inlined Images
  • Extend Cache for Images
  • Inline Images
  • Convert GIFs to PNG
  • Convert JPEGs to Progressive JPEGs
  • Collapse Whitespace
  • Local Storage Cache
  • Combine Heads
  • Extend Cache for Stylesheets
  • Combine CSS Etc......
Other available filters
  • Rewrite Domains
  • Run Experiment Module
  • Pre-Resolved DNS
  • Extend PDFs Cache
From packages or build from source on the following supported platforms:
  • CentOS/Fedora, both 32-bit and 64-bit
  • Debian/Ubuntu, both 32-bit and 64-bit
Installing Mod_Pagespeed Module in Linux
On RHEL/CentOS and Fedora
----------- On 32-bit Systems -----------------
# wget
# yum install at
# rpm -Uvh mod-pagespeed-stable_current_i386.rpm

----------- On 64-bit Systems -----------------
# wget
# yum install at
# rpm -Uvh mod-pagespeed-stable_current_x86_64.rpm

On Debian and Ubuntu
----------- On 32-bit Systems -----------------
$ wget

$ sudo dpkg -i mod-pagespeed-stable_current_i386.deb

$ sudo apt-get -f install

----------- On 64-bit Systems -----------------

$ wget

$ sudo dpkg -i mod-pagespeed-stable_current_amd64.deb

$ sudo apt-get -f install
you can update the mod_pagespeed automatically using package manager called yum or apt.
Mod_Pagespeed Configuration and Directories
The module enables following configuration files and directories Links.
  • /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.
  • pagespeed_libraries.conf : The default set of libraries for Apache, loads at Apache startup.
  • /usr/lib{lib64}/httpd/modules/ : mod_pagespeed module for Apache.
  • /var/cache/mod_pagespeed : File caching direcotry for web sites.

    Important:For Nginx You can found the mod_pagespeed conf here /usr/local/nginx/conf/ directory.
    Configuring Mod_Pagespeed Module
    For Apache mod_pagespeed automatically Start with your installation process, For Nginx you need to place following lines to your nginx.conf file .
    pagespeed on;
    # Needs to exist and be writable by nginx.  Use tmpfs for best performance.
    pagespeed FileCachePath /var/ngx_pagespeed_cache;
    # Ensure requests for pagespeed optimized resources go to the pagespeed handler
    # and no extraneous headers get set.
    location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
      add_header "" "";
    location ~ "^/pagespeed_static/" { }
    location ~ "^/ngx_pagespeed_beacon$" { } 

    Restart your Apache or Nginx server to start mod_pagespeed.

    Verifying Mod_Pagespeed Module

    To verify mod_pagespeed module use your domain or IP For Me I am using IP Address.
    # curl -D- | less
    HTTP/1.1 200 OK
    Date: Fri, 08 Mar 2016 08:19:30 GMT
    Server: Apache/2.4.6 (CentOS) PHP/5.4.16
    HTTP/1.1 200 OK
    Date: Fri, 08 Mar 2016 08:20:00 GMT
    Server: nginx/1.4.0

    If you don’t see an X-Mod-Pagespeed header, that means mod_pagespeed not working properly or Not Enable Properly.
    Turning the Module On and Off

    To turn mod_pagespeed ON, insert as the top line of pagespeed.conf:
    ModPagespeed off
    There are two ways to disable mod_pagespeed. To disable HTML rewriting but continue to serve .pagespeed. resources and parse query options (for instance for ?ModPagespeed=on) put this line in your configuration:
    ModPagespeed on

    To completely disable mod_pagespeed (.pagespeed. resources will result in 404s) use the following line:

    ModPagespeed unplugged
    Turning the Module On and Off FOR Nginx

    To turn ngx_pagespeed ON, put anywhere in your http or server block:

    pagespeed on;

    To turn ngx_pagespeed OFF, use off:
    pagespeed off;


    About Author:

    I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

    Newer Post
    Older Post


    Post a Comment