1.nginx Process Model
Nginx is a master and worker model. Master is mainly used to manage worker processes, master is compared to the boss, the worker is a wage earners, master command workers to do things. Is the Nginx process model:
Master process:
1. Receive external signals, for example: Kill-quit,kill-hup
Kill-hup Reload the configuration file, and then restart the new worker process, the old is still running, while the old worker process sends the retirement command, the old worker process finishes the original request, retires, does not receive new requests, self-destruct, The new worker process processes the new request.
2. Sending signals to individual worker processes
3. Monitor worker Processes
4. When the worker process exits abnormally, a new worker process is started automatically.
Woker Process:
Handling requests from clients
Receiving the client's connection, completing the data interaction between the server and the backend, the processes between the workers are independent and equal, and the processing opportunities for the requests are equal.
2.nginx Working principle
When the maste process starts, it creates a listener socket listener and then fork out multiple worker processes (depending on the profile), and when a request arrives, The worker process uses a shared lock to ensure that only one worker process is working on the same connection at the same time, and when the worker process receives the request, it begins to do the data response and processing, which process grabs the lock and which process requests.
Nginx is a shell, composed of the kernel and modules, mainly core, basic, third-party modules. Among them, the Core module: HTTP module, event module, mail module.
Nginx (10)--process model and working principle