您的位置:首页 > 运维架构 > Nginx

nginx 1.6.2源码分析2 499问题之upstream

2015-07-15 22:25 856 查看
upstream作为handler中一位,有重要的作用,和filter等不同的地方是,它不自己产生内容,处于处理链的上游,特殊之处也在于,他需要暂时保留一些数据,等数据回来的时候进行回复?这具体是怎么操作的?

1 upstream是如何接收请求的,接收请求的时候必然要创建一个数据结构出来,存一下啦

#0  ngx_http_upstream_init_request (r=r@entry=0x84be80) at src/http/ngx_http_upstream.c:532

#1  0x000000000043e551 in ngx_http_upstream_init (r=r@entry=0x84be80) at src/http/ngx_http_upstream.c:473

#2  0x0000000000434268 in ngx_http_read_client_request_body (r=r@entry=0x84be80, post_handler=0x43e4e6 <ngx_http_upstream_init>) at src/http/ngx_http_request_body.c:84

#3  0x000000000045ce45 in ngx_http_fastcgi_handler (r=0x84be80) at src/http/modules/ngx_http_fastcgi_module.c:649

#4  0x0000000000428529 in ngx_http_core_content_phase (r=0x84be80, ph=<optimized out>) at src/http/ngx_http_core_module.c:1410

#5  0x00000000004238e3 in ngx_http_core_run_phases (r=r@entry=0x84be80) at src/http/ngx_http_core_module.c:888

#6  0x00000000004239f2 in ngx_http_handler (r=r@entry=0x84be80) at src/http/ngx_http_core_module.c:871

#7  0x000000000042b2cb in ngx_http_process_request (r=r@entry=0x84be80) at src/http/ngx_http_request.c:1902

#8  0x000000000042d2e8 in ngx_http_process_request_headers (rev=rev@entry=0x2b716f051350) at src/http/ngx_http_request.c:1333

#9  0x000000000042d5aa in ngx_http_process_request_line (rev=rev@entry=0x2b716f051350) at src/http/ngx_http_request.c:1012

#10 0x000000000042dc93 in ngx_http_wait_request_handler (rev=0x2b716f051350) at src/http/ngx_http_request.c:499

#11 0x0000000000419416 in ngx_event_process_posted (cycle=cycle@entry=0x8400f0, posted=0x691b98 <ngx_posted_events>) at src/event/ngx_event_posted.c:40

#12 0x000000000041904b in ngx_process_events_and_timers (cycle=cycle@entry=0x8400f0) at src/event/ngx_event.c:275

#13 0x000000000041ee5f in ngx_worker_process_cycle (cycle=0x8400f0, data=<optimized out>) at src/os/unix/ngx_process_cycle.c:816

#14 0x000000000041d6d6 in ngx_spawn_process (cycle=cycle@entry=0x8400f0, proc=proc@entry=0x41ed93 <ngx_worker_process_cycle>, data=data@entry=0x1a, 

    name=name@entry=0x467e54 "worker process", respawn=respawn@entry=-3) at src/os/unix/ngx_process.c:198

#15 0x000000000041e195 in ngx_start_worker_processes (cycle=cycle@entry=0x8400f0, n=32, type=type@entry=-3) at src/os/unix/ngx_process_cycle.c:364

#16 0x000000000041f54b in ngx_master_process_cycle (cycle=cycle@entry=0x8400f0) at src/os/unix/ngx_process_cycle.c:136

#17 0x00000000004041b0 in main (argc=<optimized out>, argv=<optimized out>) at src/core/nginx.c:407

搜索源码发现 r->content_handler的赋值是在ngx_http_update_location_config中发生的:

Breakpoint 2, ngx_http_update_location_config (r=r@entry=0x84be80) at src/http/ngx_http_core_module.c:1530

1530        r->content_handler = clcf->handler;

clcf是什么呢?

    ngx_http_core_loc_conf_t  *clcf;

    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);

其中

#define ngx_http_get_module_loc_conf(r, module)  (r)->loc_conf[module.ctx_index]

clcf是r的一部分
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: