1、安装工具包 wget、vim和gcc
yum install -y wget
yum install -y vim-enhanced
yum install -y make cmake gcc gcc-c++
2、下载nginx安装包
wget http://nginx.org/download/nginx-1.6.2.tar.gz
3、安装依赖包
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
4、解压nginx-1.6.2.tar.gz
tar -zxvf nginx-1.6.2.tar.gz
5、编译安装
./configure --prefix=/usr/local/nginx
make && make install
6、启动Nginx
./usr/local/nginx/sbin/nginx
ps -ef |grep nginx
如果要关闭nginx,我们可以使用如下命令:
# /usr/local/nginx/sbin/nginx -s stop
如果想要重新热启动nginx,则使用如下命令:
# /usr/local/nginx/sbin/nginx -s reload
添加Nginx 到 service 启动
cd /etc/init.d/
vi nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: 2345 30 30
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /usr/local/nginx/logs/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
#nginx程序路径
nginxd=/usr/local/nginx/sbin/nginx
#nginx配置文件路径
nginx_config=/usr/local/nginx/conf/nginx.conf
#nginx pid文件的路径,可以在nginx的配置文件中找到
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
nginx启动、停止、无间断服务重启
# service nginx start
# service nginx stop
# service nginx reload