nginx学习:nginx的进程模型
Posted Kevin-养码青年
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx学习:nginx的进程模型相关的知识,希望对你有一定的参考价值。
概述
nginx 进程分为 master进程和work进程
1.打开配置文件查看,这里我修改为2
[root@xxx conf]# vim nginx.conf
#user nobody;
worker_processes 2;
2.重启,进入sbin 目录
./nginx -s reload
3.nginx 常用命令
./nginx -s stop # 停止
./nginx -s quit # 退出
./nginx -s reload #重启
./nginx -t #测试配置文件是否正确
4.查看
[root@xxx]# ps -ef|grep nginx
root 18496 1 0 Dec14 ? 00:00:00 nginx: master process ./nginx
nobody 28522 18496 0 09:49 ? 00:00:00 nginx: worker process
nobody 28523 18496 0 09:49 ? 00:00:00 nginx: worker process
root 28530 28497 0 09:50 pts/0 00:00:00 grep --color=auto nginx
进程模型图
这里是官网对于nginx reload的介绍
nginx -s reload
Once the master process receives the signal to reload configuration, it checks the syntax validity of the new configuration file and tries to apply the configuration provided in it. If this is a success, the master process starts new worker processes and sends messages to old worker processes, requesting them to shut down. Otherwise, the master process rolls back the changes and continues to work with the old configuration. Old worker processes, receiving a command to shut down, stop accepting new connections and continue to service current requests until all such requests are serviced. After that, the old worker processes exit.
Nginx服务不会终止,主进程检查配置,应用配置的过程。主进程会启动一个新的工作进程处理新来的请求。主进程发送消息给老的工作进程,通知老的进程不在接受请求,处理完现有的请求后退出(优雅退出)
总结
nginx的每个进程都是独立的,相互之间是安全的。一个worker 宕机了,其它work还是继续工作,相互没有影响。这里我只是入门,更多关于这方面的知识还需要学习
以上是关于nginx学习:nginx的进程模型的主要内容,如果未能解决你的问题,请参考以下文章