解決方法:
是因為nginx沒有有添加到系統服務,手動手動添加一個即可。
在 /etc/init.d/下創建名為nginx的啟動腳本即可,內容如下:
#!/bin/bash # # chkconfig: - 85 15 # description: Nginx is a World Wide Web server. # processname: nginx nginx=/usr/local/nginx/sbin/nginx conf=/usr/local/nginx/conf/nginx.conf case $1 in start) echo -n "Starting Nginx" $nginx -c $conf echo " done" ;; stop) echo -n "Stopping Nginx" killall -9 nginx echo " done" ;; test) $nginx -t -c $conf ;; reload) echo -n "Reloading Nginx" ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP echo " done" ;; restart) $0 stop $0 start ;; show) ps -aux|grep nginx ;; *) echo -n "Usage: $0 {start|restart|reload|stop|test|show}" ;; esac
保存。
注意,保存一定要保存成UNIX格式(notepad++:編輯--文檔格式轉換--轉為UNIX格式),否則會如下報錯的
設置執行權限:chmod +x /etc/init.d/nginx
注冊成服務:chkconfig
--add
nginx
設置開機啟動:chkconfig nginx on
之后,就可以使用以下命令了
service nginx start
service nginx stop
service nginx restart
service nginx reload