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 
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.8.31.4-beta.zip
unzip release-1.8.31.4-beta.zip
cd ngx_pagespeed-release-1.8.31.4-beta/
wget https://dl.google.com/dl/page-speed/psol/1.8.31.4.tar.gz
tar -xzvf 1.8.31.4.tar.gz

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:

cd
# check http://nginx.org/en/download.html for the latest version
wget http://nginx.org/download/nginx-1.6.0.tar.gz
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/nginx.pid  --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-1.8.31.4-beta --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
make
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 https://gist.github.com/sairam/5892520/raw/b8195a71e944d46271c8a49f2717f70bcd04bf1a/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