開機啓動nginxpython
首先,在linux系統的/etc/init.d/目錄下建立nginx文件,使用以下命令: vi /etc/init.d/nginx 在腳本中添加以下命令:linux
#! /bin/sh # chkconfig: 2345 08 92 # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the nginx web server PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="nginx daemon" NAME=nginx DAEMON=/home/nginx/sbin/$NAME CONFIGFILE=/home/nginx/conf/$NAME.conf PIDFILE=/home/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
接着,設置文件的訪問權限: chmod a+x /etc/init.d/nginx (a+x參數表示 ==> all user can execute 全部用戶可執行)nginx
最後將ngix加入到rc.local文件中,這樣開機的時候nginx就默認啓動了 vi /etc/rc.local 添加 /etc/init.d/nginx start 保存並退出 下次重啓就會生效,實現nginx的自啓動。web
service nginx restartspa