原文地址nginx
1.在/etc/init.d/下面建一個名叫nginx的文件ui
#! /bin/sh #chkconfig: 2345 80 90 #description:auto_run set -e PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="nginx daemon" NAME=nginx DAEMON=/usr/local/nginx/sbin/$NAME SCRIPTNAME=/etc/init.d/$NAME test -x $DAEMON || exit 0 d_start(){ $DAEMON || echo -n " already running" } d_stop(){ $DAEMON -s quit || echo -n " not running" } d_reload(){ $DAEMON -s reload || echo -n " could not reload" } d_check(){ $DAEMON -t|| echo -n " could not check config" } case $1 in start) echo -n "Starting $DESC: $NAME" d_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" d_stop echo "." ;; reload) echo -n "Reloading $DESC: configuration..." d_reload echo "reloaded." ;; check) echo -n "Checking $DESC: checking..." d_check echo "checked." ;; restart) echo -n "Restarting $DESC: $NAME" d_stop sleep 2 d_start echo "." ;; *) echo "Usage:$SCRIPTNAME {start|stop|restart|reload}" exit 3 ;; esac exit 0
2.受權腳本可執行chmod +x /etc/init.d/nginx
rest
3.命令啓動service nginx start
或/etc.init.d/nginx start
code
4.自啓動ip
Ubuntu:update-rc.d -f nginx defaults CentOS:chkconfig --add nginx chkconfig --list nginx