#!/bin/bash
#--------------------------------------------------------
# Function: Install nginx for CentOS7
# Date: 2018-1-06
# Author: Anwar Wong
#--------------------------------------------------------
#Print debug information
NGINX_VER="$?"
NGINX_SOFT="nginx-${NGINX_VER}.tar.gz"
NGINX_DIR="/usr/local/nginx"
NGINX_SRC=`echo $NGINX_SOFT| sed ‘s/.tar.*//g‘`
NGINX_YUM="yum install -y"
NGINX_ARG="--user=www --group=www --with-http_stub_status_module --with-http_ssl_module"
if [$? -eq 0]; then
echo -e " 33[32m----------------- 33[0m"
echo -e " 33[32mUsage:{/bin/bash $0 1.2.3|1.12.2} 33[0m"
exit 0
fi
#Installing dependencies
$NGINX_YUM wget make tar gcc gcc-c++ glibc zlib zlib-devel
$NGINX_YUM perl perl-devel pcre pcre-devel openssl openssl-devel
#Downloading
wget -c $NGINX_URL/$NGINX_SOFT
tar -xzf $NGINX_SOFT
cd $NGINX_SRC
#Creating user and group
useradd -s /sbin/nologin www
#Starting install nginx
./configure --prefix=$NGINX_DIR/$NGINX_ARG
#Compile nginx
make -j4
make -j4 install
#Starting Nginx
$NGINX_DIR/sbin/nginx
#Show nginx status
ps -ef |grep nginx
netstat -tnlp |grep nginx