In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article shows you how to achieve the principle analysis of nginx, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
1. Learn about the signal processing commonly used in nginx
Kill-SIGHUP $ngx_master_pid # is equivalent to nginx-s reload starting a new work process kill-SIGTERM $ngx_work_pid # rebuilding the specified nginx work process ID
Signals that can be received for the master process of nginx:
The following four signals can be achieved through nginx commands and parameters
TERM,INT says stop the nginx process immediately.
QUIT means to stop the nginx process gracefully, that is, to stop the nginx process slowly, and not to send a message to the user that immediately ends the connection, such as tcp's reset reset request.
HUP means to reload the configuration file
USR1 means to reopen the log file
The following two signals are specifically used for hot deployment of nginx, but can only be implemented through the kill of the linux command line
USR2 sends hot update signal
WINCH is used to notify offline old work processes.
When we use nginx and parameters to manage nginx on the command line, we essentially get the pid in the pid file running by the current nginx, and then send the corresponding signal to pid through the command line.
Reload-> HUP
Reopen-> USR1
Stop-> TERM
Quit-> QUIT
2. What on earth did nginx do to reload the configuration file?
What's the difference between thinking gracefully quitting and quitting immediately? Do you know?
1. Send a HUP signal to the master process (reload command) 2. The master process verifies that the configuration syntax is correct (so when we do reload It is not necessary to execute a `worker-t`) 3. The master process opens a new listening port (https may be introduced and listens 443, so the work will share the open port) 4. The master process starts a new worker child process with the new configuration. 5. The master process sends a Quit signal to the old worker child process (a nginx shutdown timeout is added in the new version of nginx, that is, when the new and old worker child processes exist at the same time Limit how long the old worker process can exit) 6. The old worker process closes the listening handle and ends the process after processing the current connection
3. What is the complete process of nginx hot upgrade?
There is a problem with the upgrade of the new worker process. Would you like to consider rolling back?
The old worker process has never been dropped?
After upgrading nginx, I found that many of the expected functions can not be used, configuration error?
When we are dealing with nginx version upgrade or add new expansion modules, we will encounter these problems more or less, familiar with the principle of nginx upgrade quickly solve these problems.
1. Replace the old nginx file with the new nginx file (pay attention to backup) 2. Send a USR2 signal to the master process. 3. The master process modifies the pid file name with the suffix .oldbin4. The master process starts the new master process 5. 5 with the new nginx file. Send a quit signal to the old master process to shut down the old master process 6. Rollback: send HUP to the old master and quit to the new master
4. How to gracefully shut down nignx's worker process?
How to close the connection gracefully? The worker process can identify whether the current process is processing the request, and if it does not process the request, it can close the connection, but when the nginx proxy websocket protocol, it can not do this, because in the websocket back-end communication in the frame frame, nginx is not parsed, so it can not be recognized. When nignx proxies a tcp request, it is impossible to determine how many packets a request has to go through before it ends, so it is impossible to identify whether the process is processing the request, but for Http requests, nginx is OK.
1. Set the timer `timeout`, and then set a graceful closing flag bit 2 for the process. Closing the listening handle is no longer receiving new connections 3. Close idle connection 4. Wait in the loop for all connections to close 5. The above content of the exit process is how to implement the principle analysis of nginx. Have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.