server{}块解析
来源:互联网 发布:限电插座淘宝 编辑:程序博客网 时间:2024/04/28 11:58
server{}块解析过程:
第一部分,同样是server块内解析,包括创建server级配置存储结构、解析server{}内配置项。
与http块解析不同的有两点:一,server的ngx_http_conf_ctx_t->main_conf不是重新创建的,而是直接指向http块的ngx_http_conf_ctx_t->main_conf,因为server块内并不存在http main配置,其http main配置复用http块的;二,需要将server块加入http的servers存储结构cmcf->servers。
第二部分,为没有listen配置的server设置默认listen,否则server块将无法工作。
static char *ngx_http_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy){ char *rv; void *mconf; ngx_uint_t i; ngx_conf_t pcf; ngx_http_module_t *module; struct sockaddr_in *sin; ngx_http_conf_ctx_t *ctx, *http_ctx; ngx_http_listen_opt_t lsopt; ngx_http_core_srv_conf_t *cscf, **cscfp; ngx_http_core_main_conf_t *cmcf; ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t)); if (ctx == NULL) { return NGX_CONF_ERROR; } /* server块配置存储结构的main_conf指向http块的main_conf */ http_ctx = cf->ctx; ctx->main_conf = http_ctx->main_conf; /* the server{}'s srv_conf */ ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); if (ctx->srv_conf == NULL) { return NGX_CONF_ERROR; } /* the server{}'s loc_conf */ ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module); if (ctx->loc_conf == NULL) { return NGX_CONF_ERROR; } for (i = 0; cf->cycle->modules[i]; i++) { if (cf->cycle->modules[i]->type != NGX_HTTP_MODULE) { continue; } module = cf->cycle->modules[i]->ctx; if (module->create_srv_conf) { mconf = module->create_srv_conf(cf); if (mconf == NULL) { return NGX_CONF_ERROR; } ctx->srv_conf[cf->cycle->modules[i]->ctx_index] = mconf; } if (module->create_loc_conf) { mconf = module->create_loc_conf(cf); if (mconf == NULL) { return NGX_CONF_ERROR; } ctx->loc_conf[cf->cycle->modules[i]->ctx_index] = mconf; } } /* the server configuration context */ /*将server块加入cmcf->servers,cmcf->servers存储着所有server块*/ cscf = ctx->srv_conf[ngx_http_core_module.ctx_index]; cscf->ctx = ctx; cmcf = ctx->main_conf[ngx_http_core_module.ctx_index]; cscfp = ngx_array_push(&cmcf->servers); if (cscfp == NULL) { return NGX_CONF_ERROR; } *cscfp = cscf; /* parse inside server{} */ pcf = *cf; cf->ctx = ctx; cf->cmd_type = NGX_HTTP_SRV_CONF; rv = ngx_conf_parse(cf, NULL); *cf = pcf; /*如果没有listen配置项,设置默认listen*/ if (rv == NGX_CONF_OK && !cscf->listen) { ngx_memzero(&lsopt, sizeof(ngx_http_listen_opt_t)); sin = &lsopt.u.sockaddr_in; sin->sin_family = AF_INET;#if (NGX_WIN32) sin->sin_port = htons(80);#else sin->sin_port = htons((getuid() == 0) ? 80 : 8000);#endif sin->sin_addr.s_addr = INADDR_ANY; lsopt.socklen = sizeof(struct sockaddr_in); lsopt.backlog = NGX_LISTEN_BACKLOG; lsopt.rcvbuf = -1; lsopt.sndbuf = -1;#if (NGX_HAVE_SETFIB) lsopt.setfib = -1;#endif#if (NGX_HAVE_TCP_FASTOPEN) lsopt.fastopen = -1;#endif lsopt.wildcard = 1; (void) ngx_sock_ntop(&lsopt.u.sockaddr, lsopt.socklen, lsopt.addr, NGX_SOCKADDR_STRLEN, 1); if (ngx_http_add_listen(cf, cscf, &lsopt) != NGX_OK) { return NGX_CONF_ERROR; } } return rv;}
ngx_http_add_listen函数说明见listen配置项解析。
0 0
- server{}块解析
- bbed 解析数据块
- http{}块解析
- PEB结构块解析
- PEB结构块解析
- SQL Server块日志恢复
- SQL Server 常用代码块
- 静态块调用顺序解析
- 【internal】oracle数据块解析
- 明明白白使用数据块 ----数据块格式深入解析
- 转 明明白白使用数据块 ----数据块格式深入解析
- 深度解析Unix中inode块与超级块
- 块设备剖析之块设备注册 - add_disk()函数解析
- Nginx的server块listen命令详解
- 文件数据块分块算法解析
- 文件数据块分块算法解析
- RMAN深入解析之--备份数据块
- java try catch块的简单解析
- 用最基础的方法实现的JSON转模型
- Unity C#调用java
- 事件处理
- 安卓中上传头像的应用
- 模板模式
- server{}块解析
- Android高德地图实现后台定位
- 面向对象(四)——继承多态
- 首尾相连的一维数组中连续子数组最大和
- CGAffineTransform 使用
- DHCP
- java异常处理
- 大连失业金领取办法
- bdqn S1 考试易错题