Install and configure Nginx PageSpeed module in a DirectAdmin Linux VPS

Posted by vpsineu on Aug 18, 2016 5:20 PM EDT
VPSinEU.com; By VPSinEU.com
Mail this story
Print this story

The following article will guide you through the steps on how to install and configure Nginx PageSpeed module in a DirectAdmin Linux VPS.

The following article will guide you through the steps on how to install and configure Nginx PageSpeed module in a DirectAdmin Linux VPS.

What is DirectAdmin?

DirectAdmin is a powerful, web-based hosting control panel which makes managing websites, databases, e-mail accounts, ftp accounts and much more on your Linux VPS much easier and much faster. More information about DirectAdmin can be found on the official website at https://www.directadmin.com

What is NGINX?

NGINX is the world’s most popular open source web server and load balancer for high-traffic sites, powering over 140 million properties world-wide. It started out as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.

What is PageSpeed?

PageSpeed is an open-source Apache HTTP Server or NGINX webserver module, which automatically applies chosen filters to pages and associated assets, such as stylesheets, JavaScript, and HTML files, as well as to images and website cache requirements. The largest advantage of this module is that it does not require modifications to existing content or workflow, meaning that all internal optimizations and changes to files are made on the server side, presenting modified files directly to the user. Each of its filters corresponds to one of Google’s web performance best practices rules.

PRE-REQUIREMENTS

A Linux VPS Hosting DirectAdmin Control Panel Nginx webserver CentOS 6 Linux OS

0. SSH TO YOUR DIRECTADMIN LINUX VPS

First thing to do is to login to your DirectAdmin virtual server via SSH and optionally fire up a screen/tmux session. For example:

ssh YOUR_VPS_IP -p YOUR_VPS_SSH_PORT screen -U -S pagespeed-screen

1. UPDATE YOUR DIRECTADMIN LINUX VPS

Next, make sure your system is fully up-to-date by running the following yum command:

yum update

2. INSTALL REQUIRED TOOLS

To successfully build and install the PageSpeed module in your DirectAdmin Linux Server, you need to make sure some required tools are setup on your server. Starting from PageSpeed version 1.10.33.0, it’s required to have a modern C++ compiler, such as gcc ? 4.8 or clang ? 3.3 to build the module. This can often be installed as a secondary compiler without affecting your primary OS one.

rpm --import https://linux.web.cern.ch/linux/scientific6/docs/repository/... wget -O /etc/yum.repos.d/slc6-devtoolset.repo https://linux.web.cern.ch/linux/scientific6/docs/repository/... yum install devtoolset-2-gcc-c++ devtoolset-2-binutils gcc-c++ pcre-devel zlib-devel make unzip

3. DOWNLOAD THE LATEST PAGESPEED VERSION

Always make sure you’re using the latest PageSpeed version available which you can get it from https://github.com/pagespeed/ngx_pagespeed/releases . Keep in mind to adjust the version in the NPS_VERSION variable below:

cd /opt NPS_VERSION=1.11.33.3 wget https://github.com/pagespeed/ngx_pagespeed/archive/release-$ {NPS_VERSION}-beta.zip -O release-${NPS_VERSION}-beta.zip unzip release-${NPS_VERSION}-beta.zip cd ngx_pagespeed-release-${NPS_VERSION}-beta/ wget https://dl.google.com/dl/page-speed/psol/$ {NPS_VERSION}.tar.gz tar -xzf ${NPS_VERSION}.tar.gz

4. COMPILE NGINX WITH PAGESPEED SUPPORT

Next step is to customize the compilation flags of your NGINX DirectAdmin installation. This is easily achieved in DirectAdmin by running the following commands:

cd /usr/local/directadmin/custombuild mkdir -p custom/nginx

and copy the original configure flags using:

cp configure/nginx/configure.nginx custom/nginx/

now edit custom/nginx/configure.nginx and include the PageSpeed module and the custom compiler as in:

vim custom/nginx/configure.nginx

#!/bin/sh ./configure "--add-module=/opt/ngx_pagespeed-release-1.11.33.3-beta" "--with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc" "--user=nginx" "--group=nginx" "--prefix=/usr" "--sbin-path=/usr/sbin" "--conf-path=/etc/nginx/nginx.conf" "--pid-path=/var/run/nginx.pid" "--http-log-path=/var/log/nginx/access_log" "--error-log-path=/var/log/nginx/error_log" "--with-ipv6" "--without-mail_imap_module" "--without-mail_smtp_module" "--with-http_ssl_module" "--with-http_realip_module" "--with-http_stub_status_module" "--with-http_gzip_static_module" "--with-http_dav_module" "--with-cc-opt='-D FD_SETSIZE=32768'"

again, make sure you adjust the PageSpeed version. Save the file and proceed with the re-compilation of NGINX using the custom configure flags. Do this by running the following commands:

./build used_configs ./build nginx

the compilation may take a while, so once it’s completed, verify the PageSpeed module is included by running:

nginx -V

5. CONFIGURE PAGESPEED

next, login to your DirectAdmin as admin, navigate to Admin Level >> Extra Features >> Custom HTTPD Configurations, choose your desired domain and paste the following:

pagespeed on; pagespeed FileCachePath /var/ngx_pagespeed_cache; pagespeed EnableFilters flatten_css_imports;

of course, you can feel free to use any other PageSpeed configuration options you feel will better suit your needs

6. TEST THE PAGESPEED MODULE

You can remotely test whether the PageSpeed is enabled for particular domain by using a simple tool like curl. For example, let’s test if the domain.com domain has PageSpeed enabled:

curl -I -s -X GET http://domain.com | grep ^X-Page-Speed

X-Page-Speed: 1.11.33.2-0

As you can see there is the X-Page-Speed attribute in the HTTP headers returned by the curl command. This indicated that PageSpeed is enabled for domain.com

Full Story

  Nav
» Read more about: Story Type: Tutorial; Groups: Linux

« Return to the newswire homepage

This topic does not have any threads posted yet!

You cannot post until you login.