Nginx – How to build a Debian package with Google PageSpeed module

nginx photo

Nginx is a high speed web server. Google Pagespeed is an Nginx add on for speeding up web pages at the web server level. This can include minifying javascript, deferring scripts, combining stylesheets and javascript, etc.

Photo by xmodulo


  1. First create and enter a build directory:

    mkdir ~/nginx && cd ~/nginx
    
  2. Next we get the source for Nginx using APT:

    apt-get source nginx
    
  3. Now we need to download the Pagespeed module, as well as PSOL, and extract both:

    cd ~
    wget https://github.com/apache/incubator-pagespeed-ngx/archive/v1.13.35.2-stable.zip
    unzip v1.13.35.2-stable.zip
    cd incubator-pagespeed-ngx-1.13.35.2-stable/
    wget https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz
    tar xvf 1.13.35.2-x64.tar.gz psol/
    
  4. Now we need to install the build dependencies for Nginx:

    apt-get build-dep nginx
    
  5. Now we need to edit the configuration for Nginx compilation to add the Pagespeed module:

    nano ~/nginx/nginx-1.16.1/debian/rules
    

    Add the following to the configure statement (changing /path/to to the real path):

    --add-module=/path/to/incubator-pagespeed-ngx-1.13.35.2-stable
    
  6. Now using the below command, compile and build the .deb package for Nginx with the Pagespeed module:

    cd ~/nginx/nginx-1.16.1/
    dpkg-buildpackage -b
    
  7. You should now have a .deb package in ~/nginx. To install this package all you need to do is use dpkg:

    dpkg -i ~/nginx/nginx_1.16.1-1~bionic_amd64.deb
    

    The package name may be different depending on the target os, in my case bionic, AKA Ubuntu 18.04.

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *