6、通过更改配置文件来控制nginx-阅读官方文档

官网:Controlling nginx

翻译部分:Changing Configuration

开始!


In order for nginx to re-read the configuration file, a HUP signal should be sent to the master process.

 为了让nginx重读配置文件,需要发送一个HUP信号给主进程。


The master process first checks the syntax validity, then tries to apply new configuration, that is, to open log files and new listen sockets.

 主进程先检查配置文件的语法合法性,然后尝试应用新的配置,也就是说,打开日志文件和新的监听套接字。


If this fails, it rolls back changes and continues to work with old configuration.

如果失败了,nginx会回滚新配置的修改,继续用旧配置工作。 


If this succeeds, it starts new worker processes, and sends messages to old worker processes requesting them to shut down gracefully.

如果成功了,nginx开启一个新的工作进程 ,并且发消息给旧的工作进程请求它们正常关闭。


Old worker processes close listen sockets and continue to service old clients.

 旧进程关闭监听套接字,继续为旧客户端服务。


After all clients are serviced, old worker processes are shut down.

 当服务完所有客户端,旧工作进程才会被关闭。


Let’s illustrate this by example.

 让我们用一个例子来验证一下。


Imagine that nginx is run on FreeBSD and the command

 假设nginx跑在FreeBSD操作系统(一种类UNIX操作系统)上,执行下面的命令:

ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx|PID)'

produces the following output:

 会得到下面的内容:

  PID  PPID USER    %CPU   VSZ WCHAN  COMMAND
33126     1 root     0.0  1148 pause  nginx: master process /usr/local/nginx/sbin/nginx
33127 33126 nobody   0.0  1380 kqread nginx: worker process (nginx)
33128 33126 nobody   0.0  1364 kqread nginx: worker process (nginx)
33129 33126 nobody   0.0  1364 kqread nginx: worker process (nginx)

 


If HUP is sent to the master process, the output becomes:

 如果发送HUP给主进程,输出内容变成:

  PID  PPID USER    %CPU   VSZ WCHAN  COMMAND
33126     1 root     0.0  1164 pause  nginx: master process /usr/local/nginx/sbin/nginx
33129 33126 nobody   0.0  1380 kqread nginx: worker process is shutting down (nginx)
33134 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)
33135 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)
33136 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)

One of the old worker processes with PID 33129 still continues to work.

其中一个id为33129的旧工作进程 依然在继续工作,还没有关闭。

工作进程由 变成了


After some time it exits:

 过了一段时间后,33129进程才退出了:

  PID  PPID USER    %CPU   VSZ WCHAN  COMMAND
33126     1 root     0.0  1164 pause  nginx: master process /usr/local/nginx/sbin/nginx
33134 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)
33135 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)
33136 33126 nobody   0.0  1368 kqread nginx: worker process (nginx)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值