制作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
来源:https://www.cnblogs.com/phplhs/p/4136133.html