天天看點

将nginx添加至service服務

一、問題描述:

  無法用service指令啟動nginx

  

将nginx添加至service服務

二、問題分析:

  /etc/init.d/目錄下缺少nginx預設啟動腳本

三、問題解決:

  在/etc/init.d/路徑下添加腳本檔案,名稱為nginx,并添加檔案可執行權限:

  

将nginx添加至service服務

  修改nginx啟動腳本檔案:  

#!/bin/bash
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
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
echo "Success."
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac      

   

四、問題驗證:

  

将nginx添加至service服務

轉載于:https://www.cnblogs.com/starfish29/p/10570362.html