static ngx_int_t ngx_http_proxy_handler(ngx_http_request_t *r) { ... ????if (ngx_http_upstream_create(r) != NGX_OK) { ????????return NGX_HTTP_INTERNAL_SERVER_ERROR; ????} ????// 设置upstream处理方法 ????rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init); ... } //紧接着分析ngx_http_upstream_init void ngx_http_upstream_init(ngx_http_request_t *r) { ... ????ngx_http_upstream_init_request(r); ... } static void ngx_http_upstream_init_request(ngx_http_request_t *r) { ... ???????if (u->resolved->sockaddr) { ????????????if (ngx_http_upstream_create_round_robin_peer(r, u->resolved) ????????????????!= NGX_OK) ????????????{ ????????????????ngx_http_upstream_finalize_request(r, u, ???????????????????????????????????????????????NGX_HTTP_INTERNAL_SERVER_ERROR); ????????????????return; ????????????} ????????????ngx_http_upstream_connect(r, u); ????????????return; ????????} ????????host = &u->resolved->host; ????????umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module); ????????// 调用connect_peer前先get_round_robin_peer ????????ngx_http_upstream_connect(r, u); ... } |