static ngx_int_t
ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)
{char *rv;void *conf, **confp;ngx_uint_t i, found;ngx_str_t *name;ngx_command_t *cmd;name = cf->args->elts;found = 0;
此时 name->data=root
for (i = 0; cf->cycle->modules[i]; i++) {cmd = cf->cycle->modules[i]->commands;if (cmd == NULL) {continue;}for ( /* void */ ; cmd->name.len; cmd++) {if (name->len != cmd->name.len) {continue;}if (ngx_strcmp(name->data, cmd->name.data) != 0) {continue;}found = 1;
循环查找 root 指令
直到 i=9
modules[9]->name=ngx_http_core_module
找到 了 root 指令
root
指令 用于指定 Nginx 服务器在响应请求时,查找静态文件的根路径
else if (cf->ctx) {confp = *(void **) ((char *) cf->ctx + cmd->conf);if (confp) {conf = confp[cf->cycle->modules[i]->ctx_index];}}
此时
cmd->conf=16
ctx_index=0ngx_http_conf_ctx_t -CSDN博客
cf->ctx + cmd->conf ,跳过前 2 个字段,指向第3个字段 loc_conf
根据索引在 数组中取出指针,它指向该 模块在 location 级对应的配置结构体
rv = cmd->set(cf, cmd, conf);
调用当前指令的 set 函数指针指向的函数,处理该指令的配置
当前 是 ngx_http_core_module 模块的 root 指令
set 指向的是 ngx_http_core_root 函数
ngx_http_core_root-CSDN博客
if (rv == NGX_CONF_OK) {return NGX_OK;}
返回 NGX_OK