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

📄 ngx_http_fastcgi_module.c

📁 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器
💻 C
📖 第 1 页 / 共 5 页
字号:
    ngx_conf_merge_msec_value(conf->upstream.read_timeout,                              prev->upstream.read_timeout, 60000);    ngx_conf_merge_size_value(conf->upstream.send_lowat,                              prev->upstream.send_lowat, 0);    ngx_conf_merge_size_value(conf->upstream.buffer_size,                              prev->upstream.buffer_size,                              (size_t) ngx_pagesize);    ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,                              8, ngx_pagesize);    if (conf->upstream.bufs.num < 2) {        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,                           "there must be at least 2 \"fastcgi_buffers\"");        return NGX_CONF_ERROR;    }    size = conf->upstream.buffer_size;    if (size < conf->upstream.bufs.size) {        size = conf->upstream.bufs.size;    }    ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,                              prev->upstream.busy_buffers_size_conf,                              NGX_CONF_UNSET_SIZE);    if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) {        conf->upstream.busy_buffers_size = 2 * size;    } else {        conf->upstream.busy_buffers_size =                                         conf->upstream.busy_buffers_size_conf;    }    if (conf->upstream.busy_buffers_size < size) {        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,             "\"fastcgi_busy_buffers_size\" must be equal or bigger than "             "maximum of the value of \"fastcgi_buffer_size\" and "             "one of the \"fastcgi_buffers\"");        return NGX_CONF_ERROR;    }    if (conf->upstream.busy_buffers_size        > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size)    {        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,             "\"fastcgi_busy_buffers_size\" must be less than "             "the size of all \"fastcgi_buffers\" minus one buffer");        return NGX_CONF_ERROR;    }    ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf,                              prev->upstream.temp_file_write_size_conf,                              NGX_CONF_UNSET_SIZE);    if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) {        conf->upstream.temp_file_write_size = 2 * size;    } else {        conf->upstream.temp_file_write_size =                                      conf->upstream.temp_file_write_size_conf;    }    if (conf->upstream.temp_file_write_size < size) {        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,             "\"fastcgi_temp_file_write_size\" must be equal or bigger than "             "maximum of the value of \"fastcgi_buffer_size\" and "             "one of the \"fastcgi_buffers\"");        return NGX_CONF_ERROR;    }    ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf,                              prev->upstream.max_temp_file_size_conf,                              NGX_CONF_UNSET_SIZE);    if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) {        conf->upstream.max_temp_file_size = 1024 * 1024 * 1024;    } else {        conf->upstream.max_temp_file_size =                                        conf->upstream.max_temp_file_size_conf;    }    if (conf->upstream.max_temp_file_size != 0        && conf->upstream.max_temp_file_size < size)    {        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,             "\"fastcgi_max_temp_file_size\" must be equal to zero to disable "             "the temporary files usage or must be equal or bigger than "             "maximum of the value of \"fastcgi_buffer_size\" and "             "one of the \"fastcgi_buffers\"");        return NGX_CONF_ERROR;    }    ngx_conf_merge_bitmask_value(conf->upstream.next_upstream,                              prev->upstream.next_upstream,                              (NGX_CONF_BITMASK_SET                               |NGX_HTTP_UPSTREAM_FT_ERROR                               |NGX_HTTP_UPSTREAM_FT_TIMEOUT));    if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) {        conf->upstream.next_upstream = NGX_CONF_BITMASK_SET                                       |NGX_HTTP_UPSTREAM_FT_OFF;    }    ngx_conf_merge_path_value(conf->upstream.temp_path,                              prev->upstream.temp_path,                              NGX_HTTP_FASTCGI_TEMP_PATH, 1, 2, 0,                              ngx_garbage_collector_temp_handler, cf);    ngx_conf_merge_value(conf->upstream.pass_request_headers,                              prev->upstream.pass_request_headers, 1);    ngx_conf_merge_value(conf->upstream.pass_request_body,                              prev->upstream.pass_request_body, 1);    ngx_conf_merge_value(conf->upstream.intercept_errors,                              prev->upstream.intercept_errors, 0);    ngx_conf_merge_ptr_value(conf->catch_stderr, prev->catch_stderr, NULL);    ngx_conf_merge_str_value(conf->index, prev->index, "");    if (conf->upstream.hide_headers == NULL        && conf->upstream.pass_headers == NULL)    {        conf->upstream.hide_headers = prev->upstream.hide_headers;        conf->upstream.pass_headers = prev->upstream.pass_headers;        conf->upstream.hide_headers_hash = prev->upstream.hide_headers_hash;        if (conf->upstream.hide_headers_hash.buckets) {            goto peers;        }    } else {        if (conf->upstream.hide_headers == NULL) {            conf->upstream.hide_headers = prev->upstream.hide_headers;        }        if (conf->upstream.pass_headers == NULL) {            conf->upstream.pass_headers = prev->upstream.pass_headers;        }    }    if (ngx_array_init(&hide_headers, cf->temp_pool, 4, sizeof(ngx_hash_key_t))        != NGX_OK)    {        return NGX_CONF_ERROR;    }    for (header = ngx_http_fastcgi_hide_headers; header->len; header++) {        hk = ngx_array_push(&hide_headers);        if (hk == NULL) {            return NGX_CONF_ERROR;        }        hk->key = *header;        hk->key_hash = ngx_hash_key_lc(header->data, header->len);        hk->value = (void *) 1;    }    if (conf->upstream.hide_headers) {        header = conf->upstream.hide_headers->elts;        for (i = 0; i < conf->upstream.hide_headers->nelts; i++) {            hk = hide_headers.elts;            for (j = 0; j < hide_headers.nelts; j++) {                if (ngx_strcasecmp(header[i].data, hk[j].key.data) == 0) {                    goto exist;                }            }            hk = ngx_array_push(&hide_headers);            if (hk == NULL) {                return NGX_CONF_ERROR;            }            hk->key = header[i];            hk->key_hash = ngx_hash_key_lc(header[i].data, header[i].len);            hk->value = (void *) 1;        exist:            continue;        }    }    if (conf->upstream.pass_headers) {        hk = hide_headers.elts;        header = conf->upstream.pass_headers->elts;        for (i = 0; i < conf->upstream.pass_headers->nelts; i++) {            for (j = 0; j < hide_headers.nelts; j++) {                if (hk[j].key.data == NULL) {                    continue;                }                if (ngx_strcasecmp(header[i].data, hk[j].key.data) == 0) {                    hk[j].key.data = NULL;                    break;                }            }        }    }    hash.hash = &conf->upstream.hide_headers_hash;    hash.key = ngx_hash_key_lc;    hash.max_size = 512;    hash.bucket_size = ngx_align(64, ngx_cacheline_size);    hash.name = "fastcgi_hide_headers_hash";    hash.pool = cf->pool;    hash.temp_pool = NULL;    if (ngx_hash_init(&hash, hide_headers.elts, hide_headers.nelts) != NGX_OK) {        return NGX_CONF_ERROR;    }peers:    if (conf->upstream.upstream == NULL) {        conf->upstream.upstream = prev->upstream.upstream;        conf->upstream.schema = prev->upstream.schema;    }    if (conf->params_source == NULL) {        conf->flushes = prev->flushes;        conf->params_len = prev->params_len;        conf->params = prev->params;        conf->params_source = prev->params_source;        if (conf->params_source == NULL) {            return NGX_CONF_OK;        }    }    conf->params_len = ngx_array_create(cf->pool, 64, 1);    if (conf->params_len == NULL) {        return NGX_CONF_ERROR;    }    conf->params = ngx_array_create(cf->pool, 512, 1);    if (conf->params == NULL) {        return NGX_CONF_ERROR;    }    src = conf->params_source->elts;    for (i = 0; i < conf->params_source->nelts; i++) {        if (ngx_http_script_variables_count(&src[i].value) == 0) {            copy = ngx_array_push_n(conf->params_len,                                    sizeof(ngx_http_script_copy_code_t));            if (copy == NULL) {                return NGX_CONF_ERROR;            }            copy->code = (ngx_http_script_code_pt)                                                  ngx_http_script_copy_len_code;            copy->len = src[i].key.len;            copy = ngx_array_push_n(conf->params_len,                                    sizeof(ngx_http_script_copy_code_t));            if (copy == NULL) {                return NGX_CONF_ERROR;            }            copy->code = (ngx_http_script_code_pt)                                                 ngx_http_script_copy_len_code;            copy->len = src[i].value.len;            size = (sizeof(ngx_http_script_copy_code_t)                       + src[i].key.len + src[i].value.len                       + sizeof(uintptr_t) - 1)                    & ~(sizeof(uintptr_t) - 1);            copy = ngx_array_push_n(conf->params, size);            if (copy == NULL) {                return NGX_CONF_ERROR;            }            copy->code = ngx_http_script_copy_code;            copy->len = src[i].key.len + src[i].value.len;            p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);            p = ngx_cpymem(p, src[i].key.data, src[i].key.len);            ngx_memcpy(p, src[i].value.data, src[i].value.len);        } else {            copy = ngx_array_push_n(conf->params_len,                                    sizeof(ngx_http_script_copy_code_t));            if (copy == NULL) {                return NGX_CONF_ERROR;            }            copy->code = (ngx_http_script_code_pt)                                                 ngx_http_script_copy_len_code;            copy->len = src[i].key.len;            size = (sizeof(ngx_http_script_copy_code_t)                    + src[i].key.len + sizeof(uintptr_t) - 1)                    & ~(sizeof(uintptr_t) - 1);            copy = ngx_array_push_n(conf->params, size);            if (copy == NULL) {                return NGX_CONF_ERROR;            }            copy->code = ngx_http_script_copy_code;            copy->len = src[i].key.len;            p = (u_char *) copy + sizeof(ngx_http_script_copy_code_t);            ngx_memcpy(p, src[i].key.data, src[i].key.len);            ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));            sc.cf = cf;            sc.source = &src[i].value;            sc.flushes = &conf->flushes;            sc.lengths = &conf->params_len;            sc.values = &conf->params;            if (ngx_http_script_compile(&sc) != NGX_OK) {                return NGX_CONF_ERROR;            }        }        code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));        if (code == NULL) {            return NGX_CONF_ERROR;        }        *code = (uintptr_t) NULL;        code = ngx_array_push_n(conf->params, sizeof(uintptr_t));        if (code == NULL) {            return NGX_CONF_ERROR;        }        *code = (uintptr_t) NULL;    }    code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));    if (code == NULL) {        return NGX_CONF_ERROR;    }    *code = (uintptr_t) NULL;    return NGX_CONF_OK;}static ngx_int_tngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,    ngx_http_variable_value_t *v, uintptr_t data){    u_char                       *p;    ngx_http_fastcgi_loc_conf_t  *flcf;    if (r->uri.len) {        v->valid = 1;        v->no_cacheable = 0;        v->not_found = 0;        flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);        if (r->uri.data[r->uri.len - 1] != '/') {            v->len = r->uri.len;            v->data = r->uri.data;            return NGX_OK;        }        v->len = r->uri.len + flcf->index.len;        v->data = ngx_palloc(r->pool, v->len);        if (v->data == NULL) {            return NGX_ERROR;        }        p = ngx_copy(v->data, r->uri.data, r->uri.len);        ngx_memcpy(p, flcf->index.data, flcf->index.len);    } else {        v->len = 0;        v->valid = 1;        v->no_cacheable = 0;        v->not_found = 0;        v->data = NULL;        return NGX_OK;    }    return NGX_OK;}static char *ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf){    ngx_http_fastcgi_loc_conf_t *lcf = conf;    ngx_url_t                    u;    ngx_str_t                   *value;    ngx_http_core_loc_conf_t    *clcf;    if (lcf-

⌨️ 快捷键说明

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