Installing nGinx in Centos from source with SSL and pagespeed

Installing nGinx in Centos from source with SSL and pagespeed

Nginx is a lightning fast a very lightweight HTTP server. Although, it is a little tricky to install and configure if you need something more profesional.
You may install nginx in centos just from official repos using yum, but if you need Google's mod_pageSpeed on it, you need to compile it from sources.
We are compiling it from sources using 1.6 version and enabling gzip and SSL for https secure connections.

First, clean and update your CentOs:

sudo yum install gcc-c++ zip unzip wget openssl pcre-dev pcre-devel zlib-devel make

Then download ngx_pagespeed:

cd ngx_pagespeed-release-
tar -xzvf

Add the nginx user and group:

adduser nginx
addgroup nginx

Keep in mind that this is a new user, if you are using a specific user for sftp, add it to nginx group in /etc/groups

Download and compile Nginx configuring all required params:

# check for the latest version
tar -xvzf nginx-1.6.0.tar.gz
cd nginx-1.6.0/
./configure --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/  --lock-path=/var/run/nginx.lock  --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --add-module=$HOME/ngx_pagespeed-release- --with-http_ssl_module --with-pcre --with-file-aio --with-mail --with-mail_ssl_module --with-http_realip_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-openssl=/usr/bin/openssl
sudo make install

To reload the configuration:

/usr/local/nginx/sbin/nginx -s reload

Do not forget to install php-fpm to execute php as fastCgi directly from nginx and get a SUPER FAST server.

To be able to manage, start, stop the service, you should also include the following script in init.d scripts folder:

wget -O /etc/init.d/nginx
chmod +x /etc/init.d/nginx

Set the service to auto start

chkconfig --add nginx
chkconfig --level 345 nginx on

Setup is complete!

Start the service

service nginx start

Share this post