设置nginx开机启动

二次信任 提交于 2020-01-26 03:46:17

  制作nginx开机启动脚本:

      vi /etc/init.d/nginx

-------------------------------以下是脚本内容--------------------------------------

#! /bin/sh
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server

PATH=$PATH:/usr/local/nginx
DESC="nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME      //根据安装目录自行调整
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf  //根据安装目录自行调整
PIDFILE=/usr/local/nginx/logs/$NAME.pid   //根据安装目录自行调整
SCRIPTNAME=/etc/init.d/$NAME

set -e
[ -x "$DAEMON" ] || exit 0

do_start() {
$DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}

do_stop() {
kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}

do_reload() {
kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
do_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
do_stop
echo "."
;;
reload|graceful)
echo -n "Reloading $DESC configuration..."
do_reload
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
do_stop
do_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac

exit 0

------------------------------------------------------------------------------------------

编辑系统启动脚本文件:

  vi /etc/rc.local //此文件是开机系统自动执行的脚本文件

   添加 /etc/init.d/nginx start

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!