How to install ngx_pagespeed with NGINX in VestaCP

This tutorial for ngx_pagespeed 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!

nginx -V

Response will be something like:

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

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

RedHat, CentOS, or Fedora

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

Let’s install ngx_pagespeed

The current version of ngx_pagespeed is 1.11.33.1. Let’s install it:

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

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

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.11.33.1-beta

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

./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.11.33.1-beta

Now let’s build NGINX.

make
make install

Now you can add the following code in between server { } in the NGINX configuration file.

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$" { }

For VestaCP users only

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

Here is a list of NGINX configuration files in VestaCP:

/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

In the templates, before:

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

Add in:

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$" { }
Once the templates have been saved, all you need to do is use the rebuild web drop down selection in the VestaCP admin control panel.

10 thoughts...

  1. Loc Nguyen says:

    Thanks very much for your tutorial. I followed it but it stopped after “make” command. The error said “make: *** No rule to make target `build’, needed by `default’. Stop.” I’m using your Perfect Server package also. When I have to do now ? Thank you!

    1. SSULLIVAN88 says:

      Hi,

      Try running this:

      yum install gcc gcc-c++ make openssl-devel

      And try again.

      1. Loc Nguyen says:

        Thank you very much, it helps !!!

  2. SSULLIVAN88 says:

    You have to configure before you can make and make install; and you need to add that bit right at the end. So now you have installed nginx type:

    nginx -V

    You will get something like this:

    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

    You need to copy/paste all of the configure arguments into a new string and add on that bit you for the pagespeed version like so:

    ./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

  3. Srđan Šajin says:

    I have installed latest nginx 1.10.1. I don’t know about this step where to add –add-module=$HOME/ngx_pagespeed-release-1.9.32.10-beta ? When i go to the folder

    cd ngx_pagespeed-release-1.11.33.1-beta/ here i need to execute these make and make install ?

    I get this:

    make: *** No targets specified and no makefile found. Stop.

  4. Srđan Šajin says:

    Hello, i have problem with installing this, can you help ?

    1. SSULLIVAN88 says:

      What errors are you getting?

      1. Srđan Šajin says:

        I cant execute this commands

        make
        make install

        1. SSULLIVAN88 says:

          But what errors are showing? Without errors I cannot help you.

          1. Srđan Šajin says:

            Hi, sorry for no reply after 2 years, i have vestacp with nginx + php-fpm on Ubuntu 16.04. I dont need to do this during installation now yes ?

            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}/

Leave a Reply

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

 

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>