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)

你可能感兴趣的:(nginx,运维)