Google Pagespeed

HOWTO Install ngx_pagespeed (Google PageSpeed) – Vesta Control Panel – Forum

By May 17, 2017No Comments

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.

Source: HOWTO Install ngx_pagespeed (Google PageSpeed) – Vesta Control Panel – Forum

Leave a Reply