nginx启动失败:Redirecting to /bin/systemctl restart nginx.service Failed to restart nginx.service: Unit nginx.service not found.

 

 解决:在/etc/init.d/下创建nginx文件作启动脚本

 1 #!/bin/bash
 2 #
 3 # chkconfig: - 85 15
 4 # description: Nginx is a World Wide Web server.
 5 # processname: nginx
 6 
 7 nginx=/usr/local/nginx/sbin/nginx
 8 conf=/usr/local/nginx/conf/nginx.conf
 9 case $1 in
10 start)
11 echo -n "Starting Nginx"
12 $nginx -c $conf
13 echo " done"
14 ;;
15 stop)
16 echo -n "Stopping Nginx"
17 killall -9 nginx
18 echo " done"
19 ;;
20 test)
21 $nginx -t -c $conf
22 ;;
23 reload)
24 echo -n "Reloading Nginx"
25 ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
26 echo " done"
27 ;;
28 restart)
29 $0 stop
30 $0 start
31 ;;
32 show)
33 ps -aux|grep nginx
34 ;;
35 *)
36 echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
37 ;;
38 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

原文:https://www.cnblogs.com/guiyishanren/p/11095449.html

posted @ 2022-10-12 21:17  冢本八云  阅读(3824)  评论(0编辑  收藏  举报