Nginx Integrating ngx pagespeed

Posted By Tarun Singhal | 25-Feb-2018

Nginx - Integrating ngx_pagespeed

Google has given us many tools and enhancements that have benefited the web world enormously.
Google released ngx_pagespeed, which is a module for NGINX that tries to apply Google’s best practices to reduce both latency and bandwidth for websites.
We can do the optimization manually, can follow the high performant workflow, but not every one has time to do so. and if there are alot of websites then putting same amount of time and focus to get overall performance is difficult.

pagespeed module require to compile it with nginx source code and there is two way to do so.
first one is to use the automated script provided by google.

bash <(curl -f -L -sS https://ngxpagespeed.com/install) \     --nginx-version latest

this script will download and install all the dependencies, then download the latest nginx and then install the ngx_pagespeed module.This script is not completly headless it may ask to you to provide addition module settings etc, configure the setting according to your environment.

Second method is to install it manually

Now to serve some files, let makes a nginx configuration.

server { 
   listen       80; 
   server_name  example.com; 

   access_log  /var/log/nginx/example-access.log combined; 

   location / { 
       root   /var/www/example; 
       index  index.html; 
   } 
} 

Now enable the ngx_pagespeed but before enabling it lets create a directory

mkdir /var/ngx_pagespeed-cache

it should be writable for nginx user

chown nginx:nginx /var/ngx_pagespeed-cache

Now we can load the module by adding these lines in the block directory.

pagespeed on; 
pagespeed FileCachePath /var/ngx_pagespeed-cache; 

Thank You

Request for Proposal

Recaptcha is required.

Sending message..