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還是繼續工作,相互沒有影響。這里我只是入門,更多關於這方面的知識還需要學習


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM