Nginx is an open source for reverse proxy server. Its light weight and high performance web server the Apache HTTP Server.
This post describe how to install NGINX server manually in your system
Download latest version from the URL : http://wiki.nginx.org/Install
Download the nginx stable version 1.6.0 using wget command and extract that file,
# cd /root
# wget http://nginx.org/download/nginx-1.6.0.tar.gz
# tar -xf nginx-1.6.0.tar.gz
# cd nginx-1.6.0
# wget http://nginx.org/download/nginx-1.6.0.tar.gz
# tar -xf nginx-1.6.0.tar.gz
# cd nginx-1.6.0
I have decided to configure few modules in Nginx as below, If you have require to add more module just add continuously,
Now, Install Nginx
# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gunzip_module --without-http_geo_module
Error 1:
checking for OS
+ Linux 2.6.32-71.29.1.el6.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
Solution : This package require some package to compile gcc, glibc, gd Install it.
# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gunzip_module --without-http_geo_module
Error 2:
Error :
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre= option.
Soluton :
HTTP rewrite module requires to install pcre-devel package
# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gunzip_module --without-http_geo_module
Error 3 :
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl= option.
Solution:
SSL modules require to install openSSL devel package
# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gunzip_module --without-http_geo_module
Finally you get an output configuration summary and Nginx paths
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
# make
# make install
# make install
The Nginx server has been installed under /usr/local/nginx directory
# cd /usr/local/nginx/
To start your NGINX service manually,
# /usr/local/nginx/sbin/nginx
Need to check whether the NGINX service is running?
# ps aux | grep nginx
root 18252 0.0 0.2 44912 1124 ? Ss 20:09 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody 18253 0.0 0.3 45340 1712 ? S 20:09 0:00 nginx: worker process
root 18255 0.0 0.1 103240 868 pts/0 S+ 20:09 0:00 grep nginx
To check Nginx port number is established,
# netstat -anp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18252/nginx
unix 3 [ ] STREAM CONNECTED 37184 18252/nginx
unix 3 [ ] STREAM CONNECTED 37183 18252/nginx
Find your Nginx server version,
# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.6.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
subsystems:
Linux provides another easy way to start service subsystems,
Create a file and add below code,
vim /etc/sysconfig/nginx
## Configuration file for the nginx service.
NGINX=/usr/local/nginx/sbin/nginx
CONFFILE=/usr/local/nginx/conf/nginx.conf
Create a file /etc/init.d/nginx and add below code
# /etc/init.d/nginx
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/nginx ]; then
. /etc/sysconfig/nginx
fi
prog=nginx
nginx=${NGINX-/usr/local/nginx/sbin/nginx}
conffile=${CONFFILE-/usr/local/nginx/conf/nginx.conf}
lockfile=${LOCKFILE-/var/lock/subsys/nginx}
pidfile=${PIDFILE-/usr/local/nginx/logs/nginx.pid}
SLEEPMSEC=100000
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon --pidfile=${pidfile} ${nginx} -c ${conffile}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} ${prog}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
killproc -p ${pidfile} ${prog} -HUP
RETVAL=$?
echo
}
upgrade() {
oldbinpidfile=${pidfile}.oldbin
configtest -q || return 6
echo -n $"Staring new master $prog: "
killproc -p ${pidfile} ${prog} -USR2
RETVAL=$?
echo
/bin/usleep $SLEEPMSEC
if [ -f ${oldbinpidfile} -a -f ${pidfile} ]; then
echo -n $"Graceful shutdown of old $prog: "
killproc -p ${oldbinpidfile} ${prog} -QUIT
RETVAL=$?
echo
else
echo $"Upgrade failed!"
return 1
fi
}
configtest() {
if [ "$#" -ne 0 ] ; then
case "$1" in
-q)
FLAG=$1
;;
*)
;;
esac
shift
fi
${nginx} -t -c ${conffile} $FLAG
RETVAL=$?
return $RETVAL
}
rh_status() {
status -p ${pidfile} ${nginx}
}
# See how we were called.
case "$1" in
start)
rh_status >/dev/null 2>&1 && exit 0
start
;;
stop)
stop
;;
status)
rh_status
RETVAL=$?
;;
restart)
configtest -q || exit $RETVAL
stop
start
;;
upgrade)
upgrade
;;
condrestart|try-restart)
if rh_status >/dev/null 2>&1; then
stop
start
fi
;;
force-reload|reload)
reload
;;
configtest)
configtest
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"
RETVAL=2
esac
exit $RETVAL
Set executable permission,
# chmod +x /etc/init.d/nginx
# /etc/init.d/nginx start
Starting nginx: [ OK ]# /etc/init.d/nginx start
# /etc/init.d/nginx stop
Stopping nginx: [ OK ]# /etc/init.d/nginx status
nginx (pid 18569) is running...find your server IP Address
# ifconfig eth0 | grep inet | awk '{ print $2 }' | head -1
addr:192.168.1.1
Put this IP address on your browser : http://192.168.1.1/
Comments (0)