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

📄 ngx_http.c

📁 Nginx是一个高性能的HTTP和反向代理服务器
💻 C
📖 第 1 页 / 共 3 页
字号:
#if (NGX_PCRE)            if (regex == 0) {                continue;            }            in_addr[a].nregex = regex;            in_addr[a].regex = ngx_palloc(cf->pool,                                       regex * sizeof(ngx_http_server_name_t));            if (in_addr[a].regex == NULL) {                return NGX_CONF_ERROR;            }            for (i = 0, s = 0; s < in_addr[a].names.nelts; s++) {                if (name[s].regex) {                    in_addr[a].regex[i++] = name[s];                }            }#endif        }        in_addr = in_port[p].addrs.elts;        last = in_port[p].addrs.nelts;        /*         * if there is the binding to the "*:port" then we need to bind()         * to the "*:port" only and ignore the other bindings         */        if (in_addr[last - 1].addr == INADDR_ANY) {            in_addr[last - 1].bind = 1;            bind_all = 0;        } else {            bind_all = 1;        }        for (a = 0; a < last; /* void */ ) {            if (!bind_all && !in_addr[a].bind) {                a++;                continue;            }            ls = ngx_listening_inet_stream_socket(cf, in_addr[a].addr,                                                  in_port[p].port);            if (ls == NULL) {                return NGX_CONF_ERROR;            }            ls->addr_ntop = 1;            ls->handler = ngx_http_init_connection;            cscf = in_addr[a].core_srv_conf;            ls->pool_size = cscf->connection_pool_size;            ls->post_accept_timeout = cscf->client_header_timeout;            clcf = cscf->ctx->loc_conf[ngx_http_core_module.ctx_index];            ls->log = *clcf->err_log;            ls->log.data = &ls->addr_text;            ls->log.handler = ngx_accept_log_error;#if (NGX_WIN32)            {            ngx_iocp_conf_t  *iocpcf;            iocpcf = ngx_event_get_conf(cf->cycle->conf_ctx, ngx_iocp_module);            if (iocpcf->acceptex_read) {                ls->post_accept_buffer_size = cscf->client_header_buffer_size;            }            }#endif            ls->backlog = in_addr[a].listen_conf->backlog;            ls->rcvbuf = in_addr[a].listen_conf->rcvbuf;            ls->sndbuf = in_addr[a].listen_conf->sndbuf;#if (NGX_HAVE_DEFERRED_ACCEPT && defined SO_ACCEPTFILTER)            ls->accept_filter = in_addr[a].listen_conf->accept_filter;#endif#if (NGX_HAVE_DEFERRED_ACCEPT && defined TCP_DEFER_ACCEPT)            ls->deferred_accept = in_addr[a].listen_conf->deferred_accept;#endif            hip = ngx_palloc(cf->pool, sizeof(ngx_http_in_port_t));            if (hip == NULL) {                return NGX_CONF_ERROR;            }            hip->port = in_port[p].port;            hip->port_text.data = ngx_palloc(cf->pool, 7);            if (hip->port_text.data == NULL) {                return NGX_CONF_ERROR;            }            ls->servers = hip;            hip->port_text.len = ngx_sprintf(hip->port_text.data, ":%d",                                             hip->port)                                 - hip->port_text.data;            in_addr = in_port[p].addrs.elts;            if (in_addr[a].bind && in_addr[a].addr != INADDR_ANY) {                hip->naddrs = 1;                done = 0;            } else if (in_port[p].addrs.nelts > 1                       && in_addr[last - 1].addr == INADDR_ANY)            {                hip->naddrs = last;                done = 1;            } else {                hip->naddrs = 1;                done = 0;            }#if 0            ngx_log_error(NGX_LOG_ALERT, cf->log, 0,                          "%ui: %V %d %ui %ui",                          a, &ls->addr_text, in_addr[a].bind,                          hip->naddrs, last);#endif            hip->addrs = ngx_pcalloc(cf->pool,                                     hip->naddrs * sizeof(ngx_http_in_addr_t));            if (hip->addrs == NULL) {                return NGX_CONF_ERROR;            }            for (i = 0; i < hip->naddrs; i++) {                hip->addrs[i].addr = in_addr[i].addr;                hip->addrs[i].core_srv_conf = in_addr[i].core_srv_conf;                if (in_addr[i].hash.buckets == NULL                    && (in_addr[i].wc_head == NULL                        || in_addr[i].wc_head->hash.buckets == NULL)                    && (in_addr[i].wc_head == NULL                        || in_addr[i].wc_head->hash.buckets == NULL))                {                    continue;                }                vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));                if (vn == NULL) {                    return NGX_CONF_ERROR;                }                hip->addrs[i].virtual_names = vn;                vn->names.hash = in_addr[i].hash;                vn->names.wc_head = in_addr[i].wc_head;                vn->names.wc_tail = in_addr[i].wc_tail;#if (NGX_PCRE)                vn->nregex = in_addr[i].nregex;                vn->regex = in_addr[i].regex;#endif            }            if (done) {                break;            }            in_addr++;            in_port[p].addrs.elts = in_addr;            last--;            a = 0;        }    }#if 0    {    u_char      address[20];    ngx_uint_t  p, a;    in_port = in_ports.elts;    for (p = 0; p < in_ports.nelts; p++) {        ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,                      "port: %d %p", in_port[p].port, &in_port[p]);        in_addr = in_port[p].addrs.elts;        for (a = 0; a < in_port[p].addrs.nelts; a++) {            ngx_inet_ntop(AF_INET, &in_addr[a].addr, address, 20);            ngx_log_debug3(NGX_LOG_DEBUG_HTTP, cf->log, 0,                           "%s:%d %p",                           address, in_port[p].port, in_addr[a].core_srv_conf);            name = in_addr[a].names.elts;            for (n = 0; n < in_addr[a].names.nelts; n++) {                 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, cf->log, 0,                                "%s:%d %V %p",                                address, in_port[p].port, &name[n].name,                                name[n].core_srv_conf);            }        }    }    }#endif    return NGX_CONF_OK;}/* * add the server address, the server names and the server core module * configurations to the port (in_port) */static ngx_int_tngx_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){    ngx_http_conf_in_addr_t  *in_addr;    if (in_port->addrs.elts == NULL) {        if (ngx_array_init(&in_port->addrs, cf->temp_pool, 4,                           sizeof(ngx_http_conf_in_addr_t))            != NGX_OK)        {            return NGX_ERROR;        }    }    in_addr = ngx_array_push(&in_port->addrs);    if (in_addr == NULL) {        return NGX_ERROR;    }    in_addr->addr = lscf->addr;    in_addr->hash.buckets = NULL;    in_addr->hash.size = 0;    in_addr->wc_head = NULL;    in_addr->wc_tail = NULL;    in_addr->names.elts = NULL;#if (NGX_PCRE)    in_addr->nregex = 0;    in_addr->regex = NULL;#endif    in_addr->core_srv_conf = cscf;    in_addr->default_server = lscf->conf.default_server;    in_addr->bind = lscf->conf.bind;    in_addr->listen_conf = &lscf->conf;#if (NGX_DEBUG)    {    u_char text[20];    ngx_inet_ntop(AF_INET, &in_addr->addr, text, 20);    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0, "address: %s:%d",                   text, in_port->port);    }#endif    return ngx_http_add_names(cf, in_addr, cscf);}/* * add the server names and the server core module * configurations to the address:port (in_addr) */static ngx_int_tngx_http_add_names(ngx_conf_t *cf, ngx_http_conf_in_addr_t *in_addr,    ngx_http_core_srv_conf_t *cscf){    ngx_uint_t               i, n;    ngx_http_server_name_t  *server_names, *name;    if (in_addr->names.elts == NULL) {        if (ngx_array_init(&in_addr->names, cf->temp_pool, 4,                           sizeof(ngx_http_server_name_t))            != NGX_OK)        {            return NGX_ERROR;        }    }    server_names = cscf->server_names.elts;    for (i = 0; i < cscf->server_names.nelts; i++) {        for (n = 0; n < server_names[i].name.len; n++) {            server_names[i].name.data[n] =                                     ngx_tolower(server_names[i].name.data[n]);        }        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, cf->log, 0,                       "name: %V", &server_names[i].name);        name = ngx_array_push(&in_addr->names);        if (name == NULL) {            return NGX_ERROR;        }        *name = server_names[i];    }    return NGX_OK;}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){    char                       *rv;    ngx_uint_t                  i;    ngx_http_core_loc_conf_t  **clcfp;    clcfp = locations->elts;    for (i = 0; i < locations->nelts; i++) {        rv = module->merge_loc_conf(cf, loc_conf[ctx_index],                                    clcfp[i]->loc_conf[ctx_index]);        if (rv != NGX_CONF_OK) {            return rv;        }        if (clcfp[i]->locations == NULL) {            continue;        }        rv = ngx_http_merge_locations(cf, clcfp[i]->locations,                                      clcfp[i]->loc_conf, module, ctx_index);        if (rv != NGX_CONF_OK) {            return rv;        }    }    return NGX_CONF_OK;}static ngx_int_tngx_http_cmp_conf_in_addrs(const void *one, const void *two){    ngx_http_conf_in_addr_t  *first, *second;    first = (ngx_http_conf_in_addr_t *) one;    second = (ngx_http_conf_in_addr_t *) two;    if (first->addr == INADDR_ANY) {        /* the INADDR_ANY must be the last resort, shift it to the end */        return 1;    }    if (first->bind && !second->bind) {        /* shift explicit bind()ed addresses to the start */        return -1;    }    if (!first->bind && second->bind) {        /* shift explicit bind()ed addresses to the start */        return 1;    }    /* do not sort by default */    return 0;}static int ngx_libc_cdeclngx_http_cmp_dns_wildcards(const void *one, const void *two){    ngx_hash_key_t  *first, *second;    first = (ngx_hash_key_t *) one;    second = (ngx_hash_key_t *) two;    return ngx_strcmp(first->key.data, second->key.data);}

⌨️ 快捷键说明

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