ngx_http_create_request function parsing

Source: Internet
Author: User

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

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.