Nginx Source Code Analysis--ngx_http_optimize_servers () function

Source: Internet
Author: User

This function does a part of the work: 1) Use port as the entry point to store the useful information in the hash table 2) call the Ngx_http_init_listening () function to listen to the port

1, in the ngx_http_core_main_conf_t structure has a field ports, is an array, the array is stored in all ngx_http_conf_port_t; for each port information (ngx_http_conf_port_t), Call

The Ngx_http_server_names function, which also calls the Ngx_http_init_listening function at the same time, first parses the Ngx_http_server_names function.

2) for each port information (ngx_http_conf_port_t), there is a field in the Addrs, which is an array, this array is all the address information (ngx_http_conf_addr_t), an address information

(ngx_http_conf_addr_t) corresponding to multiple server{} configuration blocks (ngx_http_core_srv_conf_t) 3

3) for each server{} configuration block Information (ngx_http_core_srv_conf_t) corresponds to very many sever_name. Therefore, there is an array in the ngx_http_core_srv_conf_t struct Server_ Names, the member is ngx_http_server_name_t, so that each server_name (ngx_http_server_name_t) to operate, stored in the hash table

That's it. The port (ngx_http_conf_port_t) is the entry point for all the addresses are traversed, all the server_name are stored in the hash table


Second, ngx_http_init_listening () function call

An array of port information is stored in the ngx_http_core_main_conf_t structure, and for each port the ngx_http_init_listening operation is called for each ngx_http_conf_addr_t information

Ngx_http_add_listening () function, why is each port corresponding to a very multiple address? That is to say, very many songs IP addresses are monitored on this port.

In the Ngx_http_add_listening function call ngx_create_listening, the corresponding address information to produce a ngx_listening_t structure, the most important thing is that the callback on the listener socket is NGX_HTTP_ Init_connection function, this one listens to the socket on receiving the HTTP request succeeds (after accepting succeeds after creating a new connection, call the Accept connection in the function ngx_event_accept function, this function is the most readable event callback, It is very clear that this ngx_listening_t structure includes a callback on an event structure, except that this is the Ngx_event_process_init function, which functions as Ngx_event_core_module Init_ Porcess callback, this callback is called in the Ngx_worker_process_cycle, as the worker process initialization, that is, the worker process is initialized to the listener on the socket read-only event callback set to Ngx_event_ Accep, in the Ngx_event_accept function, after the accept, directly invoke the listener socket on the handler, that is, the Ngx_http_init_connection function) started. The Ngx_http_init_connection function allows HTTP requests to enter the 11 phases of HTTP.


Nginx Source Code Analysis--ngx_http_optimize_servers () function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.