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));