创建nginx启动命令脚本
1 | vi /etc/init.d/nginx |
插入以下内容, 注意修改PATH和NAME字段, 匹配自己的安装路径
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #! /bin/bash# chkconfig: - 85 15PATH=/usr/local/nginxDESC="nginx daemon"NAME=nginxDAEMON=$PATH/sbin/$NAMECONFIGFILE=$PATH/conf/$NAME.confPIDFILE=$PATH/logs/$NAME.pidSCRIPTNAME=/etc/init.d/$NAMEset -e[ -x "$DAEMON" ] || exit 0do_start() {$DAEMON -c $CONFIGFILE || echo -n "nginx already running"}do_stop() {$DAEMON -s stop || echo -n "nginx not running"}do_reload() {$DAEMON -s reload || echo -n "nginx can't reload"}case "$1" instart)echo -n "Starting $DESC: $NAME"do_startecho ".";;stop)echo -n "Stopping $DESC: $NAME"do_stopecho ".";;reload|graceful)echo -n "Reloading $DESC configuration..."do_reloadecho ".";;restart)echo -n "Restarting $DESC: $NAME"do_stopdo_startecho ".";;*)echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2exit 3;;esacexit 0 |
设置执行权限
chmod a+x /etc/init.d/nginx
注册成服务
chkconfig --add nginx
设置开机启动
1 | chkconfig nginx on |
重启, 查看nginx服务是否自动启动
shutdown -h 0 -r netstat -apn|grep nginx
对nginx服务执行停止/启动/重新读取配置文件操作
1 2 3 4 5 6 7 8 | #启动nginx服务systemctl start nginx.service#停止nginx服务systemctl stop nginx.service#重启nginx服务systemctl restart nginx.service#重新读取nginx配置(这个最常用, 不用停止nginx服务就能使修改的配置生效)systemctl reload nginx.service |
发表评论