⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ngx_http.c

📁 Nginx是一个高性能的HTTP和反向代理服务器
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (C) Igor Sysoev */#include <ngx_config.h>#include <ngx_core.h>#include <ngx_event.h>#include <ngx_http.h>static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);static ngx_int_t ngx_http_add_address(ngx_conf_t *cf,    ngx_http_conf_in_port_t *in_port, ngx_http_listen_t *lscf,    ngx_http_core_srv_conf_t *cscf);static ngx_int_t ngx_http_add_names(ngx_conf_t *cf,    ngx_http_conf_in_addr_t *in_addr, ngx_http_core_srv_conf_t *cscf);static char *ngx_http_merge_locations(ngx_conf_t *cf,    ngx_array_t *locations, void **loc_conf, ngx_http_module_t *module,    ngx_uint_t ctx_index);static ngx_int_t ngx_http_cmp_conf_in_addrs(const void *one, const void *two);static int ngx_libc_cdecl ngx_http_cmp_dns_wildcards(const void *one,    const void *two);ngx_uint_t   ngx_http_max_module;ngx_uint_t   ngx_http_total_requests;uint64_t     ngx_http_total_sent;ngx_int_t  (*ngx_http_top_header_filter) (ngx_http_request_t *r);ngx_int_t  (*ngx_http_top_body_filter) (ngx_http_request_t *r, ngx_chain_t *ch);static ngx_command_t  ngx_http_commands[] = {    { ngx_string("http"),      NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,      ngx_http_block,      0,      0,      NULL },      ngx_null_command};static ngx_core_module_t  ngx_http_module_ctx = {    ngx_string("http"),    NULL,    NULL};ngx_module_t  ngx_http_module = {    NGX_MODULE_V1,    &ngx_http_module_ctx,                  /* module context */    ngx_http_commands,                     /* module directives */    NGX_CORE_MODULE,                       /* module type */    NULL,                                  /* init master */    NULL,                                  /* init module */    NULL,                                  /* init process */    NULL,                                  /* init thread */    NULL,                                  /* exit thread */    NULL,                                  /* exit process */    NULL,                                  /* exit master */    NGX_MODULE_V1_PADDING};static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf){    char                        *rv;    ngx_int_t                    rc, j;    ngx_uint_t                   mi, m, s, l, p, a, i, n;    ngx_uint_t                   find_config_index, use_rewrite, use_access;    ngx_uint_t                   last, bind_all, done;    ngx_conf_t                   pcf;    ngx_array_t                  headers_in, in_ports;    ngx_hash_key_t              *hk;    ngx_hash_init_t              hash;    ngx_listening_t             *ls;    ngx_http_listen_t           *lscf;    ngx_http_module_t           *module;    ngx_http_header_t           *header;    ngx_http_in_port_t          *hip;    ngx_http_handler_pt         *h;    ngx_http_conf_ctx_t         *ctx;    ngx_http_conf_in_port_t     *in_port;    ngx_http_conf_in_addr_t     *in_addr;    ngx_hash_keys_arrays_t       ha;    ngx_http_server_name_t      *name;    ngx_http_phase_handler_t    *ph;    ngx_http_virtual_names_t    *vn;    ngx_http_core_srv_conf_t   **cscfp, *cscf;    ngx_http_core_loc_conf_t    *clcf;    ngx_http_phase_handler_pt    checker;    ngx_http_core_main_conf_t   *cmcf;#if (NGX_PCRE)    ngx_uint_t                   regex;#endif    /* the main http context */    ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));    if (ctx == NULL) {        return NGX_CONF_ERROR;    }    *(ngx_http_conf_ctx_t **) conf = ctx;    /* count the number of the http modules and set up their indices */    ngx_http_max_module = 0;    for (m = 0; ngx_modules[m]; m++) {        if (ngx_modules[m]->type != NGX_HTTP_MODULE) {            continue;        }        ngx_modules[m]->ctx_index = ngx_http_max_module++;    }    /* the http main_conf context, it is the same in the all http contexts */    ctx->main_conf = ngx_pcalloc(cf->pool,                                 sizeof(void *) * ngx_http_max_module);    if (ctx->main_conf == NULL) {        return NGX_CONF_ERROR;    }    /*     * the http null srv_conf context, it is used to merge     * the server{}s' srv_conf's     */    ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);    if (ctx->srv_conf == NULL) {        return NGX_CONF_ERROR;    }    /*     * the http null loc_conf context, it is used to merge     * the server{}s' loc_conf's     */    ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);    if (ctx->loc_conf == NULL) {        return NGX_CONF_ERROR;    }    /*     * create the main_conf's, the null srv_conf's, and the null loc_conf's     * of the all http modules     */    for (m = 0; ngx_modules[m]; m++) {        if (ngx_modules[m]->type != NGX_HTTP_MODULE) {            continue;        }        module = ngx_modules[m]->ctx;        mi = ngx_modules[m]->ctx_index;        if (module->create_main_conf) {            ctx->main_conf[mi] = module->create_main_conf(cf);            if (ctx->main_conf[mi] == NULL) {                return NGX_CONF_ERROR;            }        }        if (module->create_srv_conf) {            ctx->srv_conf[mi] = module->create_srv_conf(cf);            if (ctx->srv_conf[mi] == NULL) {                return NGX_CONF_ERROR;            }        }        if (module->create_loc_conf) {            ctx->loc_conf[mi] = module->create_loc_conf(cf);            if (ctx->loc_conf[mi] == NULL) {                return NGX_CONF_ERROR;            }        }    }    pcf = *cf;    cf->ctx = ctx;    for (m = 0; ngx_modules[m]; m++) {        if (ngx_modules[m]->type != NGX_HTTP_MODULE) {            continue;        }        module = ngx_modules[m]->ctx;        mi = ngx_modules[m]->ctx_index;        if (module->preconfiguration) {            if (module->preconfiguration(cf) != NGX_OK) {                return NGX_CONF_ERROR;            }        }    }    /* parse inside the http{} block */    cf->module_type = NGX_HTTP_MODULE;    cf->cmd_type = NGX_HTTP_MAIN_CONF;    rv = ngx_conf_parse(cf, NULL);    if (rv != NGX_CONF_OK) {        *cf = pcf;        return rv;    }    /*     * init http{} main_conf's, merge the server{}s' srv_conf's     * and its location{}s' loc_conf's     */    cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];    cscfp = cmcf->servers.elts;    for (m = 0; ngx_modules[m]; m++) {        if (ngx_modules[m]->type != NGX_HTTP_MODULE) {            continue;        }        module = ngx_modules[m]->ctx;        mi = ngx_modules[m]->ctx_index;        /* init http{} main_conf's */        if (module->init_main_conf) {            rv = module->init_main_conf(cf, ctx->main_conf[mi]);            if (rv != NGX_CONF_OK) {                *cf = pcf;                return rv;            }        }        for (s = 0; s < cmcf->servers.nelts; s++) {            /* merge the server{}s' srv_conf's */            if (module->merge_srv_conf) {                rv = module->merge_srv_conf(cf,                                            ctx->srv_conf[mi],                                            cscfp[s]->ctx->srv_conf[mi]);                if (rv != NGX_CONF_OK) {                    *cf = pcf;                    return rv;                }            }            if (module->merge_loc_conf) {                /* merge the server{}'s loc_conf */                rv = module->merge_loc_conf(cf,                                            ctx->loc_conf[mi],                                            cscfp[s]->ctx->loc_conf[mi]);                if (rv != NGX_CONF_OK) {                    *cf = pcf;                    return rv;                }                /* merge the locations{}' loc_conf's */                rv = ngx_http_merge_locations(cf, &cscfp[s]->locations,                                              cscfp[s]->ctx->loc_conf,                                              module, mi);                if (rv != NGX_CONF_OK) {                    *cf = pcf;                    return rv;                }            }        }    }    /* init lists of the handlers */    if (ngx_array_init(&cmcf->phases[NGX_HTTP_POST_READ_PHASE].handlers,                       cf->pool, 1, sizeof(ngx_http_handler_pt))        != NGX_OK)    {        return NGX_CONF_ERROR;    }    if (ngx_array_init(&cmcf->phases[NGX_HTTP_SERVER_REWRITE_PHASE].handlers,                       cf->pool, 1, sizeof(ngx_http_handler_pt))        != NGX_OK)    {        return NGX_CONF_ERROR;    }    if (ngx_array_init(&cmcf->phases[NGX_HTTP_REWRITE_PHASE].handlers,                       cf->pool, 1, sizeof(ngx_http_handler_pt))        != NGX_OK)    {        return NGX_CONF_ERROR;    }    if (ngx_array_init(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers,                       cf->pool, 1, sizeof(ngx_http_handler_pt))        != NGX_OK)    {        return NGX_CONF_ERROR;    }    if (ngx_array_init(&cmcf->phases[NGX_HTTP_ACCESS_PHASE].handlers,                       cf->pool, 2, sizeof(ngx_http_handler_pt))        != NGX_OK)    {        return NGX_CONF_ERROR;    }    if (ngx_array_init(&cmcf->phases[NGX_HTTP_CONTENT_PHASE].handlers,                       cf->pool, 4, sizeof(ngx_http_handler_pt))        != NGX_OK)    {        return NGX_CONF_ERROR;    }    if (ngx_array_init(&cmcf->phases[NGX_HTTP_LOG_PHASE].handlers,                       cf->pool, 1, sizeof(ngx_http_handler_pt))        != NGX_OK)    {        return NGX_CONF_ERROR;    }    if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t))        != NGX_OK)    {        return NGX_CONF_ERROR;    }    for (header = ngx_http_headers_in; header->name.len; header++) {        hk = ngx_array_push(&headers_in);        if (hk == NULL) {            return NGX_CONF_ERROR;        }        hk->key = header->name;        hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len);        hk->value = header;    }    hash.hash = &cmcf->headers_in_hash;    hash.key = ngx_hash_key_lc;    hash.max_size = 512;    hash.bucket_size = ngx_align(64, ngx_cacheline_size);    hash.name = "headers_in_hash";    hash.pool = cf->pool;    hash.temp_pool = NULL;    if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) {        return NGX_CONF_ERROR;    }    for (m = 0; ngx_modules[m]; m++) {        if (ngx_modules[m]->type != NGX_HTTP_MODULE) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -