1. 首先配置服务脚本,建立文件 /etc/rc.d/init.d/nginx2 , 其内容如下:
#!/bin/sh
#chkconfig: 2345 10 90
#name: nginx
#description: Nginx Service Script
#
case $1 in
start)
echo "Starting Nginx..."
/usr/local/nginx2/sbin/nginx -c /usr/local/nginx2/conf/nginx.conf
;;
stop)
echo "Stopping Nginx..."
/usr/bin/killall -s QUIT nginx
;;
restart)
echo "Reloading Nginx..."
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
2. 配置自启动
chkconfig --add nginx2 //加入到自启服务中
chkconfig --level 2345 nginx2 off //调节不同系统级别启动
chkconfig --level 2345 nginx2 on //调节不同系统级别启动
chkconfig | grep nginx2 //查看状态