• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Wednesday, July 2, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System CentOS

Install Nginx with Ngx_pagespeed on CentOS 7

How VPS by How VPS
October 1, 2019
in CentOS
0
0
SHARES
75
VIEWS
Share on FacebookShare on Twitter

Contents

  1. Introduction
  2. Prerequisites
  3. Step 1: Update the system
  4. Step 2: Download dependencies
  5. Step 3: Download PageSpeed Optimization Libraries
  6. Step 4: Configure and compile Nginx
  7. Step 5: Create Startup Script
  8. Step 6: Enable ngx_pagespeed
  9. Step 6: Test
  10. Want to contribute?


Introduction

Ngx-pagespeed is an open source Nginx module that speeds up your site and reduces page load time. It does so by rewriting web pages to reduce latency and bandwidth. Ngx-pagespeed also provides many optimization filters that are used to optimize various files such as css, html, png, and jpg.

Prerequisites

  • A newly deployed Vultr instance running CentOS 7.
  • A sudo user.

Step 1: Update the system

Before installing any packages on your CentOS server instance, it is recommended to update the system. Login using the sudo user and run the following commands to update the system.

sudo yum -y update  
sudo reboot

Once the system has rebooted, log in again as the sudo user and continue with the next steps.

Step 2: Download dependencies

To install Nginx with ngx-pagespeed we have to compile Nginx from source. To do so we need to download some software by running the following command.

sudo yum -y install gcc-c++ pcre-devel zlib-devel make unzip

Next, we need to download the source code for Nginx and ngx-pagespeed.
At the time of writing, the latest stable version of is Nginx 1.12.0 and the latest ngx-pagespeed version is 1.12.34.2.

NPS_VERSION=1.12.34.2
NGINX_VERSION=1.12.0
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
wget https://github.com/pagespeed/ngx_pagespeed/archive/v${NPS_VERSION}-beta.zip

Extract the downloaded packages.

tar -xvzf nginx-${NGINX_VERSION}.tar.gz
unzip v${NPS_VERSION}-beta.zip

Step 3: Download PageSpeed Optimization Libraries

The PageSpeed Optimization Libraries (psol) are required to compile Nginx. Download and extract them in the ngx-pagespeed source directory with the following commands.

cd ngx_pagespeed-${NPS_VERSION}-beta
psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
[ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL)
wget ${psol_url}
tar -xzvf $(basename ${psol_url})
cd ..

Step 4: Configure and compile Nginx

The Nginx source can now be compiled with the pagespeed module. Go to the Nginx source directory.

cd nginx-${NGINX_VERSION}

Configure the source with the following command.

./configure --add-module=$HOME/ngx_pagespeed-${NPS_VERSION}-beta --user=nobody --group=nobody --pid-path=/var/run/nginx.pid ${PS_NGX_EXTRA_FLAGS}

Once the configuration is completed, compile Nginx with the command:

sudo make

This can take several minutes. After that you can go ahead and install the software with the command:

sudo make install

Nginx has now been installed in the directory /usr/local/nginx. For convenience, we can create the following symlinks:

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

Step 5: Create Startup Script

To be able to stop and start Nginx you have to manually create a startup script. A template for this is provided by Nginx here. Copy content of the template and insert it into the /etc/init.d/nginx file using a text editor such as nano. Also set the right permissions for the file.

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

You can now start and then add it to the default runlevels (so Nginx starts and stops along with your instance) with the command:

sudo service nginx start
sudo systemctl enable nginx

Step 6: Enable ngx_pagespeed

To enable ngx-pagespeed, start by creating a cache directory and assigning ownership for it to Nginx:

sudo mkdir -p /var/ngx_pagespeed_cache
sudo chown -R nobody:nobody /var/ngx_pagespeed_cache

Open the /etc/nginx/nginx.conf file:

sudo nano /etc/nginx/nginx.conf

And add the following lines within the server block:

##
# Pagespeed main settings

pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;

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

Finally, restart Nginx for the changes to take effect:

sudo systemctl restart nginx

Step 6: Test

To check if ngx-pagespeed was properly installed on your server, run the following command:

curl -I -p http://localhost| grep X-Page-Speed

The outpout should looks like this:

X-Page-Speed: 1.12.34.2-0

Ngx-pagespeed is now installed on your server. If you don’t get this outpout, make sure that you’ve enabled ngx-pagespeed as explained before.

Want to contribute?

You could earn up to $300 by adding new articles

Submit your article
Suggest an update
Request an article
Previous Post

Monitor Your Devices Using LibreNMS on CentOS 7

Next Post

Add IP Address Range to Your Server (CentOS/Ubuntu/Debian)

Next Post

Add IP Address Range to Your Server (CentOS/Ubuntu/Debian)

Leave a Reply Cancel reply

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

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In