- 创建执行脚本:
cd /etc/rc.d/init.d
mkdir nginx
脚本内容:
#!/bin/sh
# chkconfig: 2345 85 15
# description:auto_run
cd /usr/local/nginx/sbin
case "$1" in
start)
./nginx
;;
stop)
./nginx -s stop
;;
restart)
./nginx -s reload
;;
*)
echo "Userage: $0 {start|stop|reload}"
exit 1
esac
- 给脚本添加可执行权限
chmod 777 nginx
- 添加脚本开机启动
chkconfig --add nginx
chkconfig nginx on