February 14, 2015 · 13 min · Russ Mckendrick | Suggest Changes
I wanted to have a quick play with Googles Pagespeed module, as I use NGINX and not Apache I needed to compile NGINX from source to enable the ngx_pagespeed module. The following assumes you are have a clean CentOS 7 installation.
First off you need to install the packages which enable you to compile NGINX with ngx_pagespeed from source.
NGINX & ngx_pagespeed on CentOS 7 1/8
Now create a NGINX user and make so the user doesn’t have a shell.
NGINX & ngx_pagespeed on CentOS 7 2/8
Once the required packages have been installed and have created the NGINX user it’s time to grab a copy of the ngx_pagespeed and psol source code. See https://github.com/pagespeed/ngx_pagespeed/releases↗for latest release details.
Now you have the source its time to configure NGIX and compile
NGINX & ngx_pagespeed on CentOS 7 5/8
Now you have NGINX compiled and installed on your server. While you could manage the process manually it’s best to create an init script. As CentOS 7 uses systemd you need to create a service file in /usr/lib/systemd/system/.
NGINX & ngx_pagespeed on CentOS 7 6/8
If everything has gone as expected you should have NGINX running your server with the ngx_pagespeed module also loaded. Now you will to do playing with ngx_pagespeed, first of all create a cache directory and make sure that NGINX can read and write to it;
NGINX & ngx_pagespeed on CentOS 7 7/8
then add some directives to your NGINX virtual host block. I used to the following for my tests;