共计 1006 个字符,预计需要花费 3 分钟才能阅读完成。
编写 Nginx 启动脚本,并加入系统服务
vim /etc/init.d/nginx
#!/bin/bash
# chkconfig: – 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN=”/data/nginx/sbin/nginx”
NGINX_CONF=”/data/nginx/conf/nginx.conf”
NGINX_PID=”/data/nginx/logs/nginx.pid”
RETVAL=0
prog=”Nginx”
start() {
echo -n $”Starting $prog: ”
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop() {
echo -n $”Stopping $prog: ”
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload(){
echo -n $”Reloading $prog: ”
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart(){
stop
start
}
configtest(){
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case “$1″ in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $”Usage: $0 {start|stop|reload|restart|configtest}”
RETVAL=1
esac
exit $RETVAL
修改权限并添加到服务列表:
chmod a+x /etc/init.d/nginx
chkconfig –add nginx 加入到系统服务
chkconfig nginx on 开机自动启动
service nginx restart 启动 nginx
停止 Nginx:[确定]
正在启动 Nginx:[确定]