NGX_HTTP_REQUEST_T is an important structure, and each HTTP request will have its own ngx_http_request_t structure, and the Ngx_http_create_request function initializes a ngx_http_ REQUEST_T structure. The main code and parsing are as follows.
The requests field in the ngx_connection_t structure represents the number of requests processed by a connection, and if in long connection mode, a connection may handle several requests. Adding the $connection_requests field to the Log_format specified in the configuration file is the result obtained by this variable.
c->requests++;
The main variable in the ngx_http_request_t structure acts on the request when a child request is derived, and the child request may have its own child request, but regardless of derivation, their main variable is the highest generational request.
R->main = R;
The count variable acts when a request is derived from another request, including child requests, internal redirects, upstream, and so on. Each time a request is derived, the count value is added one.
R->count = 1;
The us_tries variable acts when the request is going through the upstream process. Assuming that n hosts are configured in the upstream block, if the first host is not successfully connected, the Ngx_http_upstream_next function is executed, which is the attempt to connect to the next host. The us_tries variable is added one at a time, compared to the number of times configured in the configuration file.
R->us_tries = 1;
The uri_changes variable acts when the URI changes, including the internal redirect, rewrite. The default is initialized to 11, each change will be reduced by one, or up to 10 times, to prevent infinite redirection or infinite rewrite cycle of this phenomenon.
R->uri_changes = ngx_http_max_uri_changes + 1;
Requests may derive child requests, but there is a limit to the number of child requests that are derived from each request, which defaults to 200 child requests. Every time a newborn becomes a child request, it adds one, and each time a child request is completed, it will be reduced by one.
r->subrequests = ngx_http_max_subrequests + 1;
ngx_http_create_request function parsing