首页 > 其他 > 详细

nginx加入到service服务

时间:2020-11-28 19:29:20      阅读:54      评论:0      收藏:0      [点我收藏+]

安装nginx后,使用命令service nginx start启动nginx服务是,无法启动,会报如下错误

技术分享图片

 

这是因为服务器未设置nginx启动脚本,那么需要在/etc/init.d/目录下创建nginx的启动文件

方法:

  执行 vi /etc/init.d/nginx

  进入文件,将以下内容复制到nginx文件,并保存

 1 #!/bin/bash
 2 #Startup script for the nginx Web Server
 3 #chkconfig: 2345 85 15
 4 nginx=/usr/local/nginx/sbin/nginx
 5 conf=/usr/local/nginx/conf/nginx.conf
 6 case $1 in
 7 start)
 8 echo -n "Starting Nginx"
 9 $nginx -c $conf
10 echo " done."
11 ;;
12 stop)
13 echo -n "Stopping Nginx"
14 killall -9 nginx
15 echo " done."
16 ;;
17 test)
18 $nginx -t -c $conf
19 echo "Success."
20 ;;
21 reload)
22 echo -n "Reloading Nginx"
23 ps auxww | grep nginx | grep master | awk ‘{print $2}‘ | xargs kill -HUP
24 echo " done."
25 ;;
26 restart)
27 $nginx -s reload
28 echo "reload done."
29 ;;
30 *)
31 echo "Usage: $0 {start|restart|reload|stop|test|show}"
32 ;;
33 esac

 

  执行 service nginx start后报无权限错误,这时候需要处理文件权限

技术分享图片

  执行  chmod 755 nginx即可,

再次启动服务

 技术分享图片

 

命令扩展:

  service nginx start 启动

  service nginx stop 关闭

  servcie nginx reload 重新加载

 参考博客:https://www.cnblogs.com/lwhctv/p/9132857.html

 

nginx加入到service服务

原文:https://www.cnblogs.com/donglovebobo/p/14052728.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!