How to add pagespeed on existent NGINX - UBUNTU server?

  • Posted on October 20, 2014
  • ramsteteAsked by ramstete

Hello, I have read many answers here, but my goal it is to install the pagespeed on ubuntu without make disasters. I have see that need to “reinstall” the nginx, but is it possible using the packages system? And which are the steps to do withotu to risk to lose the existing web portal?

Thank you very much and sorry for my poor english

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Unfortunately, the pagespeed module is not available from the official page repositories. In order to use it with Nginx, you’ll need to build Nginx from source. These directions are based on the ones from the ngx_pagespeed Google Code page, but they have been somewhat changed to be a better drop in replacement for the packaged version.

First install the build dependencies:

sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip

Then download ngx_pagespeed:

unzip release-${NPS_VERSION}
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
tar -xzvf ${NPS_VERSION}.tar.gz  # extracts to psol/

Now we’ll build Nginx with the pagespeed module (note the configure arguments are different from the version provided by upstream):

# check for the latest version
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/
./configure --add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta \
  --prefix=/usr/local/share/nginx --conf-path=/etc/nginx/nginx.conf \
  --sbin-path=/usr/local/sbin --error-log-path=/var/log/nginx/error.log
sudo make install

It should now be installed and available. Before removing the old Nginx package, we need to do one more thing. Let’s copy the init script that comes with the package and modify it to work with the new version:

cp /etc/init.d/nginx /etc/init.d/nginx-pagespeed
sed -i 's|/usr/sbin/nginx|/usr/local/sbin/nginx|g' /etc/init.d/nginx-pagespeed

Now remove the package:

sudo apt-get remove nginx*

Finally, enable pagespeed by adding the following to /etc/nginx/nginx.conf

        #ngx_pagespeed module settings

        pagespeed on;
        pagespeed FileCachePath /var/ngx_pagespeed_cache;

And start it with:

service nginx-pagespeed start

This is out of date; there’s now an automated installer for ngx_pagespeed: build_ngx_pagespeed_from_source

It’s also suggesting people build ngx_pagespeed version 1.9, which has unpatched security vulnerabilities in HTTPS fetching.

This comment has been deleted