HOWTO Install ngx_pagespeed (Google PageSpeed) Topic is solved

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
SS88
Posts: 298
Joined: Thu Nov 19, 2015 12:40 pm

HOWTO Install ngx_pagespeed (Google PageSpeed)  Topic is solved

Postby SS88 » Thu Nov 19, 2015 1:17 pm

This has only been tested with Debian 7. I will provide the alternate commands for RedHat, CentOS, or Fedora but I have not tested this.

I first installed and compired nginx from source BEFORE removing the packages incase I hit any problems, then issued the commands AGAIN to confirm it was all working. As usual - take backups!

Code: Select all

nginx -V


Response will be something like (take note bold details - we will use them later!):

nginx version: nginx/1.8.0
built by gcc 4.7.2 (Debian 4.7.2-5)
built with OpenSSL 1.0.1e 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed' --with-ipv6


Ubuntu or Debian

Code: Select all

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


RedHat, CentOS, or Fedora

Code: Select all

yum install gcc-c++ pcre-devel zlib-devel make unzip openssl-devl


The current version of ngx_pagespeed is 1.9.32.10. Let's install it:

Code: Select all

cd
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.9.32.10-beta.zip
unzip release-1.9.32.10-beta.zip
cd ngx_pagespeed-release-1.9.32.10-beta/
wget https://dl.google.com/dl/page-speed/psol/1.9.32.10.tar.gz
tar -xzvf 1.9.32.10.tar.gz


Now let's install NGINX. Replace the version number with the previous number displayed after issuing command "nginx -V"

Code: Select all

cd
NGINX_VERSION=1.8.0
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/


The configure string must be built with the above output of "nginx -V"

Use the version code of your NGINX above (mine is 1.8.0) and copy/paste the configure arguments BEFORE adding --add-module=$HOME/ngx_pagespeed-release-1.9.32.10-beta

DO NOT COPY/PASTE BELOW AS YOUR NGINX CONFIGURATION ARGUMENTS COULD BE DIFFERENT!

Code: Select all

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed' --with-ipv6 --add-module=$HOME/ngx_pagespeed-release-1.9.32.10-beta


Code: Select all

make
make install


If there are no problems then start editing the VESTA templates located in /usr/local/vesta/data/templates/web/nginx

Code: Select all

/usr/local/vesta/data/templates/web/nginx/default.tpl
/usr/local/vesta/data/templates/web/nginx/hosting.tpl
/usr/local/vesta/data/templates/web/nginx/caching.tpl

/usr/local/vesta/data/templates/web/nginx/default.stpl
/usr/local/vesta/data/templates/web/nginx/hosting.stpl
/usr/local/vesta/data/templates/web/nginx/caching.stpl


+ anymore you have.

In the templates, before:

Code: Select all

include %home%/%user%/conf/web/nginx.%domain%.conf*;


Add in:

Code: Select all

pagespeed On;
pagespeed RewriteLevel CoreFilters;

# HTTPS Support
pagespeed FetchHttps enable,allow_self_signed;

pagespeed EnableFilters lazyload_images,collapse_whitespace,insert_dns_prefetch,dedup_inlined_images,defer_javascript,pedantic,trim_urls,sprite_images,extend_cache_pdfs,remove_comments,resize_mobile_images,inline_preview_images,insert_image_dimensions,convert_to_webp_lossless,local_storage_cache,inline_google_font_css,prioritize_critical_css,rewrite_style_attributes,move_css_to_head,move_css_above_scripts,outline_javascript,outline_css,combine_heads;

pagespeed FileCachePath /var/ngx_pagespeed_cache;

location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }


If you want to speed up SSL connections when changing all .stpl templates then add:

Code: Select all

spdy

to:

Code: Select all

listen      %ip%:%proxy_ssl_port% spdy;


The code above only works if you have nginx with the --with-http_spdy_module
Most recent versions of nginx have the new --with-http_v2_module (search the output of command nginx -V). If you have --with-http_v2_module then use this code:

Code: Select all

listen      %ip%:%proxy_ssl_port% ssl http2;


Once the templates have been completed, all you need to do is rebuild web command via VESTA control panel.
Last edited by SS88 on Tue Jul 19, 2016 7:14 am, edited 1 time in total.

SS88
Posts: 298
Joined: Thu Nov 19, 2015 12:40 pm

Re: HOWTO Install ngx_pagespeed (Google PageSpeed)

Postby SS88 » Thu Nov 19, 2015 1:20 pm

ngx_pagespeed filter information can be found here:

https://developers.google.com/speed/pag ... ig_filters

rraulinio
Posts: 2
Joined: Mon Nov 23, 2015 11:30 pm

Re: HOWTO Install ngx_pagespeed (Google PageSpeed)

Postby rraulinio » Thu Dec 03, 2015 2:35 pm

Great post man, thanks a lot!

Ovidiu
Posts: 9
Joined: Tue Dec 08, 2015 2:04 pm

Re: HOWTO Install ngx_pagespeed (Google PageSpeed)

Postby Ovidiu » Tue Dec 08, 2015 2:07 pm

alternatively you could add the sources and install nginx from DotDeb: https://www.dotdeb.org/tag/nginx/

I'm just curios, if I add pagespeed to my VestCP, will it overwrite or change any of my config files I manually edit? Or maybe there is a specific way to include extra configs without interfering with VestaCP?

SS88
Posts: 298
Joined: Thu Nov 19, 2015 12:40 pm

Re: HOWTO Install ngx_pagespeed (Google PageSpeed)

Postby SS88 » Tue Dec 08, 2015 2:48 pm

Ovidiu wrote:alternatively you could add the sources and install nginx from DotDeb: https://www.dotdeb.org/tag/nginx/

I'm just curios, if I add pagespeed to my VestCP, will it overwrite or change any of my config files I manually edit? Or maybe there is a specific way to include extra configs without interfering with VestaCP?


Yes. Any changes you have made to individual client's templates will be overwritten when you use this. You will have to go back and re-edit them.

I'm not aware of any way to keep the changes and push these in without manually editing the templates.

BeKindRewind
Posts: 2
Joined: Mon Dec 14, 2015 6:31 pm

Re: HOWTO Install ngx_pagespeed (Google PageSpeed)

Postby BeKindRewind » Mon Dec 14, 2015 6:34 pm

Hi. Getting ready to try this, but confused on your last line. How do you "rebuild web command" in the Vesta Control Panel? Did you mean restart web?

SS88
Posts: 298
Joined: Thu Nov 19, 2015 12:40 pm

Re: HOWTO Install ngx_pagespeed (Google PageSpeed)

Postby SS88 » Mon Dec 14, 2015 6:42 pm

BeKindRewind wrote:Hi. Getting ready to try this, but confused on your last line. How do you "rebuild web command" in the Vesta Control Panel? Did you mean restart web?


Nope.

  • Login to Vesta
  • Use the checkbox next to the users
  • Select "rebuild web" from drop-down (top right near search box)

BeKindRewind
Posts: 2
Joined: Mon Dec 14, 2015 6:31 pm

Re: HOWTO Install ngx_pagespeed (Google PageSpeed)

Postby BeKindRewind » Tue Dec 15, 2015 5:07 pm

Thanks! Great tutorial!

delebash
Posts: 22
Joined: Mon Aug 24, 2015 5:28 pm

Re: HOWTO Install ngx_pagespeed (Google PageSpeed)

Postby delebash » Thu Jun 16, 2016 11:21 pm

Sytem Info
Clean ubuntu 14.04 Digital Ocean droplet
Vesta nginx only option for install

Ran script to compile nginx from source with openssl for alpn support and pagespeed mod

I am getting an error on ./configure with the nginx flags

Code: Select all

configuring additional dynamic modules
adding module in debian/extra/njs-1c50334fbea6/nginx
./configure: error: no debian/extra/njs-1c50334fbea6/nginx/config was found
make: *** No rule to make target `build', needed by `default'.  Stop.
sudo: unable to resolve host vestacp
make: *** No rule to make target `install'.  Stop.


I am using the flags from my nginx -V output

Code: Select all

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-openssl=/opt/openssl-$OPENSSL_VERSION --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_perl_module=dynamic --add-dynamic-module=debian/extra/njs-1c50334fbea6/nginx --with-threads --with-stream --with-stream_ssl_module --with-http_slice_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_v2_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --add-module=/opt/ngx_pagespeed-release-$NPS_VERSION-beta



I am not sure what this is debian/extra/njs-1c50334fbea6/nginx/config
I installed these supporting build files

Code: Select all

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


Note: if I use the OP's flags substituting my openssl and pagespeed build and http2 instead of spdy the build works fine.

I
removed the debian/extra option and was able to build nginx but I also had to install a few more packages that I want to make sure are the correct ones

How is it that the below packages where not already installed since the installed nginx had a dependency on these packages

apt-get install libgd2-xpm-dev
apt-get install libxml2-dev libxslt1-dev
apt-get install libgeoip-dev
apt-get install libperl-dev

When searching for the GD2 package I also ran across php5-gd I wasn't sure which ones to install and ended up installing libgd2-xpm-dev. Geoip also had a php5 package but I installed libgeoop-dev instead. I am not even need or want to use these packages but they where listed in the default vesta nginx -V install.

Once I removed the debian/extra and installed the above packages nginx built successfully.

I am very much a novice in this area.

If you need my full build.sh file I will post it. I have google for this error but have not been able to find any results

Thanks for the help

delebash
Posts: 22
Joined: Mon Aug 24, 2015 5:28 pm

Re: HOWTO Install ngx_pagespeed (Google PageSpeed)

Postby delebash » Tue Jun 21, 2016 4:22 am

Still not sure why the original install had certain module dependencies already installed but on recompile they where not available. I just went with the apt-get libs I listed in my original post as that worked.

Code: Select all

apt-get install libgd2-xpm-dev
apt-get install libxml2-dev libxslt1-dev
apt-get install libgeoip-dev
apt-get install libperl-dev


As far as the njs or nginScript you can just download the source and compile it in nginx as per normal when adding a new module.


Return to “Web Server”



Who is online

Users browsing this forum: Google [Bot] and 4 guests