Google PageSpeed is very helpful when you want to optimize your website speed. You can test your website speed on Google PageSpeed here. Google PageSpeed also provide a module for your server to optimize your content delivery currently they support NGINX and Apache. In this tutorial, I will explain to you how to configure PageSpeed on your NGINX Server. For this tutorial, I am using Digital Ocean Droplet you can create your account using this link and get a credit of 10$ in your account. Now not wasting any time I can give simple step which you can follow to Install NGINX, PHP, MySQL and PageSpeed on your cloud or in Digital Ocean Droplet.

Configure GooglePage Speed with NGINX

Install NGINX, PHP, and MySQL Server on Droplet

Step 1. First login to your server using a terminal. Once login successfully to your server run below commands. First, we can update our local packages using apt

Step 2. Now after updating and indexing packages we can now install NGINX to our server using below command.

Step 3. Now we can allow some port in our NGINX using commands.

Run all above commands one by one and after running all this command check firewall status using below command.

Step 4. Now if everything works fine you can open your browser and type your IP address in address bar and hit enter you will get the welcome page of NGINX.

Install NGINX on server

Step 5. Now we can install MySQL on our server run below command

after running this command server prompt you to enter a password and confirm the password for your MySQL.

Step 6. Now install PHP using FastCGI process manager PHP-FPM run below command to install by default it will install PHP 7.0 version on the server.

Step 7. Now open default configure file of fpm/php.ini and search for cgi.fix_pathinfo and uncomment this and set its value to 0

Open the file in the editor using below command

and to search press cntrl+w and enter the term and hit enter and remove the comment and set the value to 0.

Now restart your PHP FPM using below command

Configure NGINX to run PHP

To configure NGINX to run with PHP we need to edit default virtual host of NGINX, to do so run below command to open default config file.

Remove comments from the open file so that your file looks like this

Now verify your editing and reload the configuration

Now we can check if PHP is running or not to create a file in which we can check phpinfo

and enter this code

save file and exit from the editor.

Open browser enters your IP address/info.php and you can check your phpinfo page.

PHP File Configuration

Now we successfully install NGINX, PHP, and MySQL on our server.

Configure PageSpeed with NGINX server

To configure PageSpeed follow simple steps. You can also check the official documentation here.

Step 1.  Run Automated install to install all dependencies and the latest version of PageSpeed Module

Step 2. When the installation process is running it will prompt you to add some extra configuration. Below is some recommended module you can add them to your configuration.

Step 3. You will ask to build NGINX press Y and hit enter to continue.

Step 4. If your build is successful you get this message as shown in below screenshot

If successfully installed and you get the message as shown above you need to restart your server.

Step 5. Now create PageSpeed Cache folder check if not create at this location first at this location./var/cache/ngx_pagespeed/ If not then create one with owner access

Step 6. Now add PageSpeed to your server block in your NGINX virtual hosts.

To edit your default host file enter below command in your terminal

after this add code inside server block.

You need to add this code to your server block. After adding code to your default virtual host your file looks like this.

Now verify your editing and restart NGINX

Now PageSpeed Configuration part is done.

Test if PageSpeed module is running (on NGINX)

To test page speed is running on the server you open the terminal and enter the command

Configure GooglePage Speed with NGINX

If your output contains X-Page-Speed then its mean page speed is working on your server but if not then follow simple steps to verify your installation of PageSpeed.

Step 1. Login to your server and enter

Now look for page speed if unable to find that its mean PageSpeed is not installed on the server you can recheck installation steps.

Configure GooglePage Speed with NGINX

Step 2. If you find page speed in module list but still page speed is not working then you can do one more thing you can create pagespeed.conf  inside NGINX config.d folder

Configure GooglePage Speed with NGINX

and add below code in that file

Now after this try again hope this trick will work for you. Please share and like this post if this helps.

Get $10 free from Digital ocean using this link:  Digital Ocean Droplet