登录  /  注册

Linux下创建nginx脚本-start、stop、reload…,nginx-start_PHP教程

php中文网
发布: 2016-07-13 10:21:31
原创
1110人浏览过

Linux下创建nginx脚本-start、stop、reload…,nginx-start

1、关闭nginx
利用ps -aux | grep nginx 查看nginx是否启动 如果启动了就kill杀死
2、创建/etc/init.d/nginx文件

root@dnnp:~/software/nginx-1.2.3# vim /etc/init.d/nginx
登录后复制

3、添加权限并启动

root@dnnp:~/software/nginx-1.2.3# chmod +x /etc/init.d/nginx
root@dnnp:~/software/nginx-1.2.3# /etc/init.d/nginx start
Starting nginx: nginx.
root@dnnp:~/software/nginx-1.2.3# ps -aux | grep nginx
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
root   25078 0.0 0.0  4596  700 ?    Ss  14:20  0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody  25079 0.0 0.1  4820 1056 ?    S  14:20  0:00 nginx: worker process
root   25081 0.0 0.0  3304  768 pts/0  S+  14:20  0:00 grep nginx
root@dnnp:~/software/nginx-1.2.3#
登录后复制

注:/etc/init.d/nginx文件内容如下

#! /bin/sh
 
### BEGIN INIT INFO
# Provides:     nginx
# Required-Start:  $all
# Required-Stop:   $all
# Default-Start:   2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: starts the nginx web server
# Description:    starts nginx using start-stop-daemon
### END INIT INFO
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nginx/sbin/nginx
NAME=nginx
DESC=nginx
 
test -x $DAEMON || exit 0
 
# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
  . /etc/default/nginx
#    . /usr/local/nginx/conf
fi
 
set -e
 
. /lib/lsb/init-functions
 
case "$1" in
 start)
  echo -n "Starting $DESC: "
  start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
    --exec $DAEMON -- $DAEMON_OPTS || true
  echo "$NAME."
  ;;
 stop)
  echo -n "Stopping $DESC: "
  start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
    --exec $DAEMON || true
  echo "$NAME."
  ;;
 restart|force-reload)
  echo -n "Restarting $DESC: "
  start-stop-daemon --stop --quiet --pidfile \
    /usr/local/nginx/logs/$NAME.pid --exec $DAEMON || true
  sleep 1
  start-stop-daemon --start --quiet --pidfile \
    /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
  echo "$NAME."
  ;;
 reload)
   echo -n "Reloading $DESC configuration: "
   start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
     --exec $DAEMON || true
   echo "$NAME."
   ;;
 status)
   status_of_proc -p /usr/local/nginx/logs/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
   ;;
 *)
  N=/etc/init.d/$NAME
  echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2
  exit 1
  ;;
esac
 
exit 0
登录后复制

linux下怎重启nginx

在nginx的早期版本,nginx重启需要通过kill命令向nginx发送信号来实现nginx的重启。
但是,现在,nginx增加了-s选项,实现nginx的停止,重新加载功能。
1. 如果是平滑的重启nginx,可以用./nginx -s reload命令实现nginx的平滑重启。
2. 如果是非平滑重启,则可以先停止nginx,然后再启动:
./nginx -s stop && ./nginx

当我们修改nginx配置后,希望重启nginx以便让nginx生效,此时为了保证nginx在重启阶段还能够提供正常的服务,一般采用平滑重启的方式(reload)重启nginx。此时,nginx会加载新的配置,然后fork出新的worker进程。同时,master进程会向老的worker进程发送信号,告诉老的worker进程当前的情况。老的worker进程受到master进程的信号后,如果当时没有处理请求则会退出,如果正在处理请求,则老的worker进程会处理完请求然后退出。nginx就是通过这种方式去reload新的配置,从而使得在重启的过程中,仍然可以提供服务。
 

重启 nginx ,出现该命令,接下来输入什命令

start 启动服务 stop 停止服务 reload 重读配置 restart 重启服务
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/856991.htmlTechArticleLinux下创建nginx脚本-start、stop、reload…,nginx-start 1、关闭nginx 利用ps -aux | grep nginx 查看nginx是否启动 如果启动了就kill杀死 2、创建/etc/init...
智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号