nginx啟動失敗:Redirecting to /bin/systemctl start nginx.service Failed to start nginx.service: Unit not found.


 

解決方法:

是因為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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM