How To Install Nginx With ngx_pagespeed on CentOS

Install Nginx With ngx_pagespeed on CentOS

For those of you who didn’t know, PageSpeed (ngx_pagespeed) is a 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 souce 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.

Install Nginx With ngx_pagespeed on CentOS

Step 1. Install dependencies

yum install gcc-c++ pcre-devel pcre-devel zlib-devel make unzip openssl-devel

Step 2. Download and install ngx_pagespeed and PSOL (PageSpeed Optimization Libraries) source code as follows.

mkdir -p /opt/nginx/modules
cd /opt/nginx/modules
cd ngx_pagespeed-release-
tar -xzf

Step 3. Download the latest stable version of Nginx from here and build it with ngx_pagespeed support.

## cd /opt/nginx/
## wget
## tar -zxf nginx-1.6.2.tar.gz
## cd nginx-1.6.2/
## ./configure --add-module=/opt/nginx/modules/ngx_pagespeed-release- \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/run/ \
--lock-path=/run/lock/subsys/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--user=nginx \

## make
## make install

Step 4. You can verify that ngx_pagespeed module has been added to Nginx installation using the following command

nginx version: nginx/1.6.2
built by gcc 4.8.2 20131212 (Red Hat 4.8.2-7) (GCC)
configure arguments: --add-module=/usr/local/nginx/modules/ngx_pagespeed- . . . .

Step 5. Configure ngx_pagespeed module in Nginx

nano /etc/nginx/nginx.conf

# enable ngx_pagespeed
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;

Step 6. Create a file cache directory which will be written by Nginx.

mkdir /var/ngx_pagespeed_cache
chown nginx:nginx /var/ngx_pagespeed_cache

Step 7. Create an init script for Nginx.

wget -O /etc/init.d/nginx
chmod 0755 /etc/init.d/nginx
chown root:root /etc/init.d/nginx

Step 8. Finally, start Nginx.

service nginx start

Congratulation’s! You have successfully installed Nginx with ngx_pagespeed. Thanks for using this tutorial for installing Nginx with ngx_pagespeed on CentOS system. For additional help or useful information, we recommend you to check the official Nginx web site.

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 a best deal!