How To Install Nginx With ngx_pagespeed on CentOS

Install Nginx With ngx_pagespeed on CentOS

In this tutorial, we will show you how to install Nginx with ngx_pagespeed on CentOS. For those of you who didn’t know, PageSpeed (ngx_pagespeed) is an Nginx module created by Google to help Make the Web Faster by rewriting web pages to reduce latency and bandwidth. For the installation, we will need to compile Nginx from the source with the PageSpeed module, as Nginx doesn’t support Dynamic module loading (DSO) unless you want to build your own rpm or deb files.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Nginx With ngx_pagespeed on the CentOS server.


  • A server running one of the following operating systems: CentOS or RHEL-based.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies for Nginx.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Nginx With ngx_pagespeed on CentOS

Step 1. The first step is to update your system to the latest version of the package list. To do so, run the following commands:

sudo dnf check-update

Step 2. Installing Nginx Web Server.

By default, Nginx is not available on the CentOS base repository. Now run the following command below to add Nginx stable repository to your system:

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

Once the repository is added, you can install Nginx by running the following command:

sudo dnf install nginx

To verify that the latest version of Nginx has been installed, run:

nginx -v

Step 3. Installing ngx_pagespeed.

To install ngx_pagespeed, you need to add the ngx_pagespeed repository to your system. You can do this by running the following command below:

sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Once the repository is added, you can install ngx_pagespeed by running the following command:

sudo dnf install ngx_pagespeed

Step 4. Configuring Nginx.

After Nginx and ngx_pagespeed are installed, you need to configure Nginx to use ngx_pagespeed. You can do this by editing the Nginx configuration file located at /etc/nginx/nginx.conf.

nano /etc/nginx/nginx.conf

Add the following lines at the beginning of the file:

load_module "/usr/lib64/nginx/modules/ngx_pagespeed.so";

pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;

Save and close the file, then you can start Nginx by running the following command:

sudo systemctl start nginx
sudo systemctl enable nginx

Congratulations! You have successfully installed Nginx with ngx_pagespeed. Thanks for using this tutorial for installing Nginx with ngx_pagespeed on the CentOS system. For additional help or useful information, we recommend you check the official Nginx website.

Nginx Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “Nginx Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!



r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button