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

📄 ngx_http_core_module.c

📁 Nginx是一个高性能的HTTP和反向代理服务器
💻 C
📖 第 1 页 / 共 5 页
字号:
      offsetof(ngx_http_core_loc_conf_t, msie_refresh),      NULL },    { ngx_string("log_not_found"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,      ngx_conf_set_flag_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, log_not_found),      NULL },    { ngx_string("recursive_error_pages"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,      ngx_conf_set_flag_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, recursive_error_pages),      NULL },    { ngx_string("server_tokens"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,      ngx_conf_set_flag_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, server_tokens),      NULL },    { ngx_string("error_page"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF                        |NGX_CONF_2MORE,      ngx_http_core_error_page,      NGX_HTTP_LOC_CONF_OFFSET,      0,      NULL },    { ngx_string("post_action"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF                        |NGX_CONF_TAKE1,      ngx_conf_set_str_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, post_action),      NULL },    { ngx_string("error_log"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,      ngx_http_core_error_log,      NGX_HTTP_LOC_CONF_OFFSET,      0,      NULL },    { ngx_string("open_file_cache"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,      ngx_http_core_open_file_cache,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, open_file_cache),      NULL },    { ngx_string("open_file_cache_valid"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,      ngx_conf_set_sec_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),      NULL },    { ngx_string("open_file_cache_retest"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,      ngx_conf_set_sec_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, open_file_cache_valid),      &ngx_conf_deprecated_open_file_cache_retest },    { ngx_string("open_file_cache_min_uses"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,      ngx_conf_set_num_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, open_file_cache_min_uses),      NULL },    { ngx_string("open_file_cache_errors"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,      ngx_conf_set_flag_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, open_file_cache_errors),      NULL },    { ngx_string("open_file_cache_events"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,      ngx_conf_set_flag_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, open_file_cache_events),      NULL },    { ngx_string("resolver"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,      ngx_http_core_resolver,      NGX_HTTP_LOC_CONF_OFFSET,      0,      NULL },    { ngx_string("resolver_timeout"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,      ngx_conf_set_msec_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, resolver_timeout),      NULL },#if (NGX_HTTP_GZIP)    { ngx_string("gzip_vary"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,      ngx_conf_set_flag_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, gzip_vary),      NULL },    { ngx_string("gzip_http_version"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,      ngx_conf_set_enum_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, gzip_http_version),      &ngx_http_gzip_http_version },    { ngx_string("gzip_proxied"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,      ngx_conf_set_bitmask_slot,      NGX_HTTP_LOC_CONF_OFFSET,      offsetof(ngx_http_core_loc_conf_t, gzip_proxied),      &ngx_http_gzip_proxied_mask },    { ngx_string("gzip_disable"),      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,      ngx_http_gzip_disable,      NGX_HTTP_LOC_CONF_OFFSET,      0,      NULL },#endif      ngx_null_command};static ngx_http_module_t  ngx_http_core_module_ctx = {    ngx_http_core_preconfiguration,        /* preconfiguration */    NULL,                                  /* postconfiguration */    ngx_http_core_create_main_conf,        /* create main configuration */    ngx_http_core_init_main_conf,          /* init main configuration */    ngx_http_core_create_srv_conf,         /* create server configuration */    ngx_http_core_merge_srv_conf,          /* merge server configuration */    ngx_http_core_create_loc_conf,         /* create location configuration */    ngx_http_core_merge_loc_conf           /* merge location configuration */};ngx_module_t  ngx_http_core_module = {    NGX_MODULE_V1,    &ngx_http_core_module_ctx,             /* module context */    ngx_http_core_commands,                /* module directives */    NGX_HTTP_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 ngx_str_t  ngx_http_core_get_method = { 3, (u_char *) "GET " };voidngx_http_handler(ngx_http_request_t *r){    ngx_http_core_main_conf_t  *cmcf;    r->connection->log->action = NULL;    r->connection->unexpected_eof = 0;    if (!r->internal) {        switch (r->headers_in.connection_type) {        case 0:            if (r->http_version > NGX_HTTP_VERSION_10) {                r->keepalive = 1;            } else {                r->keepalive = 0;            }            break;        case NGX_HTTP_CONNECTION_CLOSE:            r->keepalive = 0;            break;        case NGX_HTTP_CONNECTION_KEEP_ALIVE:            r->keepalive = 1;            break;        }        if (r->keepalive && r->headers_in.msie && r->method == NGX_HTTP_POST) {            /*             * MSIE may wait for some time if an response for             * a POST request was sent over a keepalive connection             */            r->keepalive = 0;        }        if (r->headers_in.content_length_n > 0) {            r->lingering_close = 1;        } else {            r->lingering_close = 0;        }        r->phase_handler = 0;    } else {        cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);        r->phase_handler = cmcf->phase_engine.server_rewrite_index;    }    if (r->unparsed_uri.len) {        r->valid_unparsed_uri = 1;    }    r->valid_location = 1;    r->gzip = 0;    r->write_event_handler = ngx_http_core_run_phases;    ngx_http_core_run_phases(r);}voidngx_http_core_run_phases(ngx_http_request_t *r){    ngx_int_t                   rc;    ngx_http_phase_handler_t   *ph;    ngx_http_core_main_conf_t  *cmcf;    cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);    ph = cmcf->phase_engine.handlers;    while (ph[r->phase_handler].checker) {        rc = ph[r->phase_handler].checker(r, &ph[r->phase_handler]);        if (rc == NGX_OK) {            return;        }    }}ngx_int_tngx_http_core_generic_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph){    ngx_int_t  rc;    /*     * generic phase checker,     * used by the post read, server rewrite, rewrite, and pre-access phases     */    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                   "generic phase: %ui", r->phase_handler);    rc = ph->handler(r);    if (rc == NGX_OK) {        r->phase_handler = ph->next;        return NGX_AGAIN;    }    if (rc == NGX_DECLINED) {        r->phase_handler++;        return NGX_AGAIN;    }    if (rc == NGX_AGAIN || rc == NGX_DONE) {        return NGX_OK;    }    /* rc == NGX_ERROR || rc == NGX_HTTP_...  */    ngx_http_finalize_request(r, rc);    return NGX_OK;}ngx_int_tngx_http_core_find_config_phase(ngx_http_request_t *r,    ngx_http_phase_handler_t *ph){    u_char                    *p;    size_t                     len;    ngx_int_t                  rc;    ngx_http_core_loc_conf_t  *clcf;    ngx_http_core_srv_conf_t  *cscf;    r->content_handler = NULL;    r->uri_changed = 0;    cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);    rc = ngx_http_core_find_location(r, &cscf->locations, cscf->regex_start, 0);    if (rc == NGX_HTTP_INTERNAL_SERVER_ERROR) {        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);        return NGX_OK;    }    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);    if (!r->internal && clcf->internal) {        ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);        return NGX_OK;    }    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                   "using configuration \"%s%V\"",                   (clcf->noname ? "*" : (clcf->exact_match ? "=" : "")),                   &clcf->name);    ngx_http_update_location_config(r);    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                   "http cl:%O max:%O",                   r->headers_in.content_length_n, clcf->client_max_body_size);    if (r->headers_in.content_length_n != -1        && !r->discard_body        && clcf->client_max_body_size        && clcf->client_max_body_size < r->headers_in.content_length_n)    {        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                      "client intended to send too large body: %O bytes",                      r->headers_in.content_length_n);        ngx_http_finalize_request(r, NGX_HTTP_REQUEST_ENTITY_TOO_LARGE);        return NGX_OK;    }    if (rc == NGX_HTTP_LOCATION_AUTO_REDIRECT) {        r->headers_out.location = ngx_list_push(&r->headers_out.headers);        if (r->headers_out.location == NULL) {            ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);            return NGX_OK;        }        /*         * we do not need to set the r->headers_out.location->hash and         * r->headers_out.location->key fields         */        if (r->args.len == 0) {            r->headers_out.location->value = clcf->name;        } else {            len = clcf->name.len + 1 + r->args.len;            p = ngx_palloc(r->pool, len);            if (p == NULL) {                ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);                return NGX_OK;            }            r->headers_out.location->value.len = len;            r->headers_out.location->value.data = p;            p = ngx_cpymem(p, clcf->name.data, clcf->name.len);            *p++ = '?';            ngx_memcpy(p, r->args.data, r->args.len);        }        ngx_http_finalize_request(r, NGX_HTTP_MOVED_PERMANENTLY);        return NGX_OK;    }    r->phase_handler++;    return NGX_AGAIN;}ngx_int_tngx_http_core_post_rewrite_phase(ngx_http_request_t *r,    ngx_http_phase_handler_t *ph){    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                   "post rewrite phase: %ui", r->phase_handler);    if (!r->uri_changed) {        r->phase_handler++;        return NGX_AGAIN;    }    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                   "uri changes: %d", r->uri_changes);    /*     * gcc before 3.3 compiles the broken code for     *     if (r->uri_changes-- == 0)     * if the r->uri_changes is defined as     *     unsigned  uri_changes:4     */    r->uri_changes--;    if (r->uri_changes == 0) {        ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                      "rewrite or internal redirection cycle "                      "while processing \"%V\"", &r->uri);        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);        return NGX_OK;    }    r->phase_handler = ph->next;    return NGX_AGAIN;}ngx_int_tngx_http_core_access_phase(ngx_http_request_t *r, ngx_http_phase_handler_t *ph){    ngx_int_t                  rc;    ngx_http_core_loc_conf_t  *clcf;    if (r != r->main) {        r->phase_handler = ph->next;        return NGX_AGAIN;    }    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                   "access phase: %ui", r->phase_handler);    rc = ph->handler(r);    if (rc == NGX_DECLINED) {        r->phase_handler++;        return NGX_AGAIN;    }    if (rc == NGX_AGAIN || rc == NGX_DONE) {        return NGX_OK;    }    clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);    if (clcf->satisfy == NGX_HTTP_SATISFY_ALL) {        if (rc == NGX_OK) {            r->phase_handler++;            return NGX_AGAIN;        }    } else {        if (rc == NGX_OK) {            r->access_code = 0;            if (r->headers_out.www_authenticate) {                r->headers_out.www_authenticate->hash = 0;            }            r->phase_handler = ph->next;            return NGX_AGAIN;        }        if (rc == NGX_HTTP_FORBIDDEN || rc == NGX_HTTP_UNAUTHORIZED) {            r->access_code = rc;            r->phase_handler++;            return NGX_AGAIN;        }    }    /* rc == NGX_ERROR || rc == NGX_HTTP_...  */

⌨️ 快捷键说明

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