将nginx添加至service服务

时间:2019-03-21 11:39:09   收藏:0   阅读:964

一、问题描述:

  无法用service命令启动nginx

  技术分享图片

二、问题分析:

  /etc/init.d/目录下缺少nginx默认启动脚本

三、问题解决:

  在/etc/init.d/路径下添加脚本文件,名称为nginx,并添加文件可执行权限:

  技术分享图片

 

 

  修改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

   

四、问题验证:

  技术分享图片

原文:https://www.cnblogs.com/starfish29/p/10570362.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!