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

在這裏插入圖片描述
解決方法:
是因爲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

發佈了28 篇原創文章 · 獲贊 7 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章