1.设置PATH,设置之后可直接使用nginx指令
设置步骤参照另一篇博客:http://blog.csdn.net/cxy1620541673/article/details/48630017
2.自启动
在目录 /etc/init.d/ 中 添加脚本 nginx
脚本内容在最后补上
添加启动项
[root@localhost ~]# chkconfig --add nginx
[root@localhost ~]# chkconfig nginx on
完成
脚本内容:
#!/bin/bash
#
# chkconfig: 2345 95 5
# processname: nginx
NginxName=nginx
NginxPath=/usr/local/nginx
NginxCommand=$NginxPath/sbin/$NginxName
NginxPidFile=$NginxPath/run/nginx.pid
start(){
echo -n "nginx is starting......"
if [ -e $NginxPidFile ]; then
RES=`cat $NginxPidFile`
fi
if [ -e $NginxPidFile ] && [ "`ps -p $RES | grep $NginxName`" != "" ]; then
echo "FAILED: Nginx already running"
else
$NginxCommand
if [ $? -eq 0 ]; then
echo "SUCCESS"
else
echo "FAILED: unknow reason"
fi
fi
}
stop(){
echo -n "nginx is stopping......"
if [ -e $NginxPidFile ] ; then
$NginxCommand -s stop
if [ $? -eq 0 ]; then
echo "SUCCESS"
fi
else
echo "FAILED: Nginx is not running"
fi
}
restart(){
stop
start
}
reload(){
echo -n "nginx is reloading......"
if [ -e $NginxPidFile ] ; then
$NginxCommand -s reload
if [ $? -eq 0 ]; then
echo "SUCCESSs"
else
echo "FAILED: Nginx reload fail"
fi
else
echo "FAILED: Nginx is not running"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart|reload}"
exit 1
esac
exit 2