/usr/local/nginx/sbin/nginx -s reload #重启
/usr/local/nginx/sbin/nginx -s stop #停止
创建脚本:
cd /etc/init.d/
vim nginx.sh
添加以下代码到nginx.sh:
#!/bin/sh
#chkconfig:2345 80 90
#decription:auto_run
log_path='/usr/local/logs/autoStart.log';
#error information direct to the log
exec 2>>$log_path;
exec 1>>$log_path;
#method for echo message to the log
print(){
echo [`date +"%Y-%m-%d %T"`]: $1>>$log_path;
}
#main
/usr/local/nginx/sbin/nginx;
print "启动成功";
:wq保存退出.
自启动脚本赋予权限:
chmod +x nginx.sh
chkconfig --add nginx.sh
因为log_path下的目录/usr/local/logs/autoStart.log目前没有,需要先创建:
cd /usr/local
mkdir logs
确认是否设置自启动成功
完成以上步骤以后需要通过重启服务器
reboot
再次通过ssh连接服务器,连上之后通过命令查看是否启动成功
ps -ef |grep nginx
1724

被折叠的 条评论
为什么被折叠?



