一、问题描述
1、安装完nginx后,无法使用service或systemctl命令管理nginx服务
二、问题分析
1、/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
四、问题验证
1、service命令