location的配置过程以及http流程中的使用情况
来源:互联网 发布:dnd跑团软件 编辑:程序博客网 时间:2024/04/28 19:28
先看看ngx_http_init_listening,在系列文章中已经提到过这个函数,他的第三个参数port是一个结构体,定义如下
typedef struct {
ngx_int_t family;
in_port_t port;
ngx_array_t addrs; /* array of ngx_http_conf_addr_t */
} ngx_http_conf_port_t;
前面2个成员变量的含义不言自明,第三个变量addrs是一个数组,填写的是什么呢,是一个叫做ngx_http_conf_addr_t的结构体:
typedef struct {
ngx_http_listen_opt_t opt;
ngx_hash_t hash;
ngx_hash_wildcard_t *wc_head;
ngx_hash_wildcard_t *wc_tail;
#if (NGX_PCRE)
ngx_uint_t nregex;
ngx_http_server_name_t *regex;
#endif
/* the default server configuration for this address:port */
ngx_http_core_srv_conf_t *default_server;
ngx_array_t servers; /* array of ngx_http_core_srv_conf_t */
} ngx_http_conf_addr_t;
他有2个比较重要的成员,opt包含了真实的ip地址,default_server指向这个地址端口对应的配置文件中的默认server{}配置块,servers则指向匹配的所有server块。
然后调用定义一个hport,并调用ngx_http_add_addrs把addrs数组的值传递给hport的addrs成员,特别是把default_server传递过来。最后,hport会指向ls->servers,这个值会在ngx_http_init_connection里面用到。
跳转到这个函数,看看他的具体代码:
hc = ngx_pcalloc(c->pool, sizeof(ngx_http_connection_t));
if (hc == NULL) {
ngx_http_close_connection(c);
return;
}
c->data = hc;
/* find the server configuration for the address:port */
port = c->listening->servers;
首先根据c->listening->servers找到port,并搜索port->addrs中与c->local_sockaddr相等的地址,然后把他的成员conf传递给hc->addr_conf,hc是一个指向c->data的ngx_http_connect_t的结构体指针,再看下面这句代码:
hc->conf_ctx = hc->addr_conf->default_server->ctx;
hc->conf_ctx 的定义如下
typedef struct {
void **main_conf;
void **srv_conf;
void **loc_conf;
} ngx_http_conf_ctx_t;
这样,hc包含了一个ngx_connection_t对应的所有ngx_http_core_srv_conf_t和ngx_http_core_loc_conf_t。
最后在ngx_http_create_request中,这些指针会传递给ngx_http_request_t的成员:
r->main_conf = hc->conf_ctx->main_conf;
r->srv_conf = hc->conf_ctx->srv_conf;
r->loc_conf = hc->conf_ctx->loc_conf;
每个独立http请求都会通过NGX_HTTP_FIND_CONFIG_PHASE这个阶段,对应的函数是:ngx_http_core_find_config_phase
因为location是放在二叉树结构中,该函数最重要的动作就是递归调用ngx_http_core_find_location,通过ngx_http_regex_exec来匹配r->uri。如果匹配成功就返回,否则继续递归调用,
- location的配置过程以及http流程中的使用情况
- mediarecorder中的方法以及工作流程的过程
- mediarecorder中的方法以及工作流程的过程
- Android之mediarecorder中的方法以及工作流程的过程
- glance 使用http作为location的样式
- weblogic + apache 配置 当两个location重叠的情况
- SVN的安装与常用功能使用以及解决安装配置过程中的一些错误
- SVN的安装与常用功能使用以及解决安装配置过程中的一些错误
- SVN的安装与常用功能使用以及解决安装配置过程中的一些错误
- python 使用过程中的各种小情况
- Nginx配置中的location
- solr的配置以及流程
- location的解析过程
- nginx中的location使用
- mapreduce的执行流程以及shuffle过程
- AWR 的使用以及过程中的注意内容
- SQLSERVER2008安装以及配置过程中的问题
- butterknife8.4.0的配置使用以及在library中的使用
- 1077: [SCOI2008]天平
- SynchronousQueue 同步队列
- DOM的学习笔记
- Socket 断线重连问题
- Unity笔记——物理引擎中碰撞器(Collider)的运用
- location的配置过程以及http流程中的使用情况
- mp4v2同时录制视频和声音播放时会在中途自动终止的解决方法
- 一段文字中插入一张图片(lable,textview为例)
- getApplication()、getApplicationContext()、getBaseContext()、MainActivity.this、this
- 大数据权威戴文波特:当人机共存成定局,认识两者极限便是决策者的义务
- 关于Fragment 不响应onActivityResult的情况分析
- iOS 设计模式详解Demo
- 你不知道的Kettle学习笔记2--kettle的常用操作
- 全球首个微信应用号开发教程!