Thanks to the modular design of nginx, it is very convenient to use nginx for modular development, but it also brings about the problem of complex code and difficulty in reading, First, let’s take a look at how the http module is prepared. The function (or handler, handle) that actually handles http requests is ngx_http_wait_request_handler.
rev->handler = ngx_http_wait_request_handler;
Taking this function as an example, let’s take a look at how the http module mounts this handler, as shown below
ngx_http_block () is a typical module function in nginx. This function will be called when the entire module is loaded.
After the handler is hung, when will this handler be called?
This depends on the event module of nginx. The function implemented by the event module is to register the fd used for accept in epoll. When a client request comes, a new connfd is generated, and then Take out a connection from the connection pool, initialize the connection (that is, write the callback of our read and write events and other things into the connection), and then register it together with epoll. In this way, as long as the connfd is ready, The handler of the corresponding read and write event can be called according to the read and write status of fd.
Let’s take a look at how the event module is initialized and then monitored for accept_fd:
The above is the detailed content of How to develop nginx after installation. For more information, please follow other related articles on the PHP Chinese website!