Translator
 
 
 
 

 

 

Transla

Installation guide for the PageSpeed ​​module, which is designed to automatically optimize the site by reducing the loading time of the site in the browser.

ngx_pagespeed (or simply pagespeed) is an Nginx module designed to automatically optimize website performance by reducing the website load time in the browser.

Download source code and dependencies

First you need to update the system to the latest stable version:

sudo yum update -y

Next, download all the programs you need to compile and test:

sudo yum install wget curl unzip gcc-c++ pcre-devel zlib-devel  

Next, create a folder in your home directory to download the Nginx package.

mkdir ~/custom-nginx  

Open this folder:

cd ~/custom-nginx  

Next, download the source Nginx package from the official site.

sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz  
[root@kvmde54-19861 custom-nginx]# sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz  
--2020-06-24 15:15:43--  http://nginx.org/download/nginx-1.16.1.tar.gz
Resolving nginx.org (nginx.org)... 2001:1af8:4060:a004:21::e3, 62.210.92.35, 95.211.80.227  
Connecting to nginx.org (nginx.org)|2001:1af8:4060:a004:21::e3|:80... connected.  
HTTP request sent, awaiting response... 200 OK  
Length: 1032630 (1008K) [application/octet-stream]  
Saving to: 'nginx-1.16.1.tar.gz'  

100%[========================================================>] 1,032,630   --.-K/s   in 0.1s  

2020-06-24 15:15:43 (10.1 MB/s) - 'nginx-1.16.1.tar.gz' saved [1032630/1032630]

Unpack the resulting archive:

sudo tar zxvf nginx-1.16.1.tar.gz  

Request the content of the
/ custom-nginx folder:

ls ~/custom-nginx  

The command will show the output:

[root@kvmde54-19861 custom-nginx]# ls ~/custom-nginx
nginx-1.16.1  nginx-1.16.1.tar.gz  

To add the ngx_pagespeed module, you must first open the modules folder in the nginx-1.16.1 directory:

cd nginx-1.16.1/src/http/modules/  

In this directory, you need to download the ngx_pagespeed archive from the Github repository.

sudo wget https://github.com/pagespeed/ngx_pagespeed/archive/master.zip  

After the download is complete, unzip the archive:

sudo unzip master.zip  

For convenience, rename it to ngx_pagespeed:

sudo mv incubator-pagespeed-ngx-master ngx_pagespeed  

Open the directory:

cd ngx_pagespeed  

Load the PageSpeed ​​Optimization Libraries (psol) package required for compilation into it:

sudo wget https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz  

Finally, extract the psol archive into the ngx_pagespeed directory:

sudo tar -xzvf 1.13.35.2-x64.tar.gz  

Setting up and compiling the source code

Now you need to edit the Nginx code and add the pagespeed module to it. Open the parent directory of the Nginx code:

cd ~/custom-nginx/nginx-1.16.1/  

We look at the configuration of the already installed nginx on the system:

# nginx -V
nginx -V  
nginx version: nginx/1.16.1  
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)  
built with OpenSSL 1.0.2k-fips  26 Jan 2017  
TLS SNI support enabled  
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

Let's build nginx from sources:

# sudo ./configure __параметры_у_старого_nginx_ --add-module=:
sudo ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=./src/http/modules/ngx_pagespeed/  

After trying to build Nginx, an error may occur:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library  
into the system, or build the OpenSSL library statically from the source  
with nginx by using --with-openssl=<path> option.  

In this case, you need to install the missing packages and try again:

yum install libssl-dev  
и  
yum install -y openssl-devel  

After completing the configuration, start compiling:

sudo make  

After that, you can install the program:

sudo make install  

After that we will see that the module has been added:

[root@kvmde54-19861 nginx-1.16.1]# nginx -V
nginx version: nginx/1.16.1  
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)  
built with OpenSSL 1.0.2k-fips  26 Jan 2017  
TLS SNI support enabled  
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=./src/http/modules/ngx_pagespeed/

A custom Nginx installation is stored in the / usr / local / nginx directory. Now we need to create two symbolic links.

One of them is for the configuration file:

sudo ln -s /usr/local/nginx/conf/ /etc/nginx  

The configuration files will now be available in the /etc/nginx/ directory.

The second link is to the main binary in the /usr/sbin/ directory. To do this, run the command:

sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx  

Creating a startup script

The previous installation process creates the necessary user and group accounts for Nginx to run.

First, create a new file in the /etc/init.d/ directory:

sudo nano /etc/init.d/nginx  

Then follow this link, copy the script and paste it into the file.

Make the script executable by running the command:

sudo chmod +x /etc/init.d/nginx  

After that, you can start Nginx:

sudo service nginx start  

To have Nginx start and stop automatically with the server, add the following command to the runlevels:

sudo chkconfig nginx on  

Enabling the pagespeed module

After installing the Nginx server you need to enable ngx_pagespeed.

But first you need to create a folder in which the module can store the cache of site files:

sudo mkdir -p /var/ngx_pagespeed_cache  

Transfer the rights to this folder to the Nginx user so that the web server has the required level of access.

sudo chown -R nobody:nobody /var/ngx_pagespeed_cache  

Open the main Nginx configuration file, nginx.conf, for editing:

sudo nano /etc/nginx/nginx.conf  

Add the following lines to the http block:

# Pagespeed main settings
pagespeed on;  
pagespeed FileCachePath /var/ngx_pagespeed_cache;  

The pagespeed configuration needs to be added to the server block and the changes saved:

Installation guide for the PageSpeed ​​module, which is designed to automatically optimize the site by reducing the loading time of the site in the browser.

ngx_pagespeed (or simply pagespeed) is an Nginx module designed to automatically optimize website performance by reducing the website load time in the browser.

Download source code and dependencies

First you need to update the system to the latest stable version:

sudo yum update -y

Next, download all the programs you need to compile and test:

sudo yum install wget curl unzip gcc-c++ pcre-devel zlib-devel  

Next, create a folder in your home directory to download the Nginx package.

mkdir ~/custom-nginx  

Open this folder:

cd ~/custom-nginx  

Next, download the source Nginx package from the official site.

sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz  
[root@kvmde54-19861 custom-nginx]# sudo wget http://nginx.org/download/nginx-1.16.1.tar.gz  
--2020-06-24 15:15:43--  http://nginx.org/download/nginx-1.16.1.tar.gz
Resolving nginx.org (nginx.org)... 2001:1af8:4060:a004:21::e3, 62.210.92.35, 95.211.80.227  
Connecting to nginx.org (nginx.org)|2001:1af8:4060:a004:21::e3|:80... connected.  
HTTP request sent, awaiting response... 200 OK  
Length: 1032630 (1008K) [application/octet-stream]  
Saving to: 'nginx-1.16.1.tar.gz'  

100%[========================================================>] 1,032,630   --.-K/s   in 0.1s  

2020-06-24 15:15:43 (10.1 MB/s) - 'nginx-1.16.1.tar.gz' saved [1032630/1032630]

Unpack the resulting archive:

sudo tar zxvf nginx-1.16.1.tar.gz  

Request the content of the
/ custom-nginx folder:

ls ~/custom-nginx  

The command will show the output:

[root@kvmde54-19861 custom-nginx]# ls ~/custom-nginx
nginx-1.16.1  nginx-1.16.1.tar.gz  

To add the ngx_pagespeed module, you must first open the modules folder in the nginx-1.16.1 directory:

cd nginx-1.16.1/src/http/modules/  

In this directory, you need to download the ngx_pagespeed archive from the Github repository.

sudo wget https://github.com/pagespeed/ngx_pagespeed/archive/master.zip  

After the download is complete, unzip the archive:

sudo unzip master.zip  

For convenience, rename it to ngx_pagespeed:

sudo mv incubator-pagespeed-ngx-master ngx_pagespeed  

Open the directory:

cd ngx_pagespeed  

Load the PageSpeed ​​Optimization Libraries (psol) package required for compilation into it:

sudo wget https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz  

Finally, extract the psol archive into the ngx_pagespeed directory:

sudo tar -xzvf 1.13.35.2-x64.tar.gz  

Setting up and compiling the source code

Now you need to edit the Nginx code and add the pagespeed module to it. Open the parent directory of the Nginx code:

cd ~/custom-nginx/nginx-1.16.1/  

We look at the configuration of the already installed nginx on the system:

# nginx -V
nginx -V  
nginx version: nginx/1.16.1  
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)  
built with OpenSSL 1.0.2k-fips  26 Jan 2017  
TLS SNI support enabled  
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

Let's build nginx from sources:

# sudo ./configure __параметры_у_старого_nginx_ --add-module=:
sudo ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=./src/http/modules/ngx_pagespeed/  

After trying to build Nginx, an error may occur:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library  
into the system, or build the OpenSSL library statically from the source  
with nginx by using --with-openssl=<path> option.  

In this case, you need to install the missing packages and try again:

yum install libssl-dev  
и  
yum install -y openssl-devel  

After completing the configuration, start compiling:

sudo make  

After that, you can install the program:

sudo make install  

After that we will see that the module has been added:

[root@kvmde54-19861 nginx-1.16.1]# nginx -V
nginx version: nginx/1.16.1  
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)  
built with OpenSSL 1.0.2k-fips  26 Jan 2017  
TLS SNI support enabled  
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --add-module=./src/http/modules/ngx_pagespeed/

A custom Nginx installation is stored in the / usr / local / nginx directory. Now we need to create two symbolic links.

One of them is for the configuration file:

sudo ln -s /usr/local/nginx/conf/ /etc/nginx  

The configuration files will now be available in the /etc/nginx/ directory.

The second link is to the main binary in the /usr/sbin/ directory. To do this, run the command:

sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx  

Creating a startup script

The previous installation process creates the necessary user and group accounts for Nginx to run.

First, create a new file in the /etc/init.d/ directory:

sudo nano /etc/init.d/nginx  

Then follow this link, copy the script and paste it into the file.

Make the script executable by running the command:

sudo chmod +x /etc/init.d/nginx  

After that, you can start Nginx:

sudo service nginx start  

To have Nginx start and stop automatically with the server, add the following command to the runlevels:

sudo chkconfig nginx on  

Enabling the pagespeed module

After installing the Nginx server you need to enable ngx_pagespeed.

But first you need to create a folder in which the module can store the cache of site files:

sudo mkdir -p /var/ngx_pagespeed_cache  

Transfer the rights to this folder to the Nginx user so that the web server has the required level of access.

sudo chown -R nobody:nobody /var/ngx_pagespeed_cache  

Open the main Nginx configuration file, nginx.conf, for editing:

sudo nano /etc/nginx/nginx.conf  

Add the following lines to the http block:

# Pagespeed main settings
pagespeed on;  
pagespeed FileCachePath /var/ngx_pagespeed_cache;  

The pagespeed configuration needs to be added to the server block and the changes saved:

# Ensure requests for pagespeed optimized resources go to the pagespeed
# handler and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }  
location ~ "^/ngx_pagespeed_static/" { }  
location ~ "^/ngx_pagespeed_beacon" { }  

Restart Nginx:

sudo service nginx restart  

Now let's check if the module is working or not. You can check it by running the following command:

curl -I -p http://localhost  

You should see the following output:

[root@kvmde54-19861 /]# curl -I -p http://localhost
HTTP/1.1 200 OK  
Server: nginx  
Content-Type: text/html  
Connection: keep-alive  
Keep-Alive: timeout=30  
Date: Thu, 25 Jun 2020 15:07:35 GMT  
X-Page-Speed: 1.13.35.2-0  
Cache-Control: max-age=0, no-cache  

You should see the X-Page-Speed ​​and version number in the output above. This means that you have successfully installed Ngx_pagespeed on the server.

Was this answer helpful? 0 Users Found This Useful (0 Votes)