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

📄 ngx_http_fastcgi_module.c

📁 nginx 反向代理0.7.1版本 用于实现反向代理
💻 C
📖 第 1 页 / 共 5 页
字号:
                              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, "");    hash.max_size = 512;    hash.bucket_size = ngx_align(64, ngx_cacheline_size);    hash.name = "fastcgi_hide_headers_hash";    if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream,                                            &prev->upstream,                                            ngx_http_fastcgi_hide_headers,                                            &hash)        != NGX_OK)    {        return NGX_CONF_ERROR;    }    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->upstream.schema.len) {        return "is duplicate";    }    value = cf->args->elts;    ngx_memzero(&u, sizeof(ngx_url_t));    u.url = value[1];    u.no_resolve = 1;    lcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);    if (lcf->upstream.upstream == NULL) {        return NGX_CONF_ERROR;    }    lcf->upstream.schema.len = sizeof("fastcgi://") - 1;    lcf->upstream.schema.data = (u_char *) "fastcgi://";    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);    clcf->handler = ngx_http_fastcgi_handler;    if (clcf->name.data[clcf->name.len - 1] == '/') {        clcf->auto_redirect = 1;    }    return NGX_CONF_OK;}static char *ngx_http_fastcgi_store(ngx_conf_t *cf, ngx_command_t *cmd, void *conf){    ngx_http_fastcgi_loc_conf_t *flcf = conf;    ngx_str_t                  *value;    ngx_http_script_compile_t   sc;    if (flcf->upstream.store != NGX_CONF_UNSET || flcf->upstream.store_lengths)    {        return "is duplicate";    }    value = cf->args->elts;    if (ngx_strcmp(value[1].data, "on") == 0) {        flcf->upstream.store = 1;        return NGX_CONF_OK;    }    if (ngx_strcmp(value[1].data, "off") == 0) {        flcf->upstream.store = 0;        return NGX_CONF_OK;    }    /* include the terminating '\0' into script */    value[1].len++;    ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));    sc.cf = cf;    sc.source = &value[1];    sc.lengths = &flcf->upstream.store_lengths;    sc.values = &flcf->upstream.store_values;    sc.variables = ngx_http_script_variables_count(&value[1]);    sc.complete_lengths = 1;    sc.complete_values = 1;    if (ngx_http_script_compile(&sc) != NGX_OK) {        return NGX_CONF_ERROR;    }    return NGX_CONF_OK;}static char *ngx_http_fastcgi_lowat_check(ngx_conf_t *cf, void *post, void *data){#if (NGX_FREEBSD)    ssize_t *np = data;    if ((u_long) *np >= ngx_freebsd_net_inet_tcp_sendspace) {        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,                           "\"fastcgi_send_lowat\" must be less than %d "                           "(sysctl net.inet.tcp.sendspace)",                           ngx_freebsd_net_inet_tcp_sendspace);        return NGX_CONF_ERROR;    }#elif !(NGX_HAVE_SO_SNDLOWAT)    ssize_t *np = data;    ngx_conf_log_error(NGX_LOG_WARN, cf, 0,                       "\"fastcgi_send_lowat\" is not supported, ignored");    *np = 0;#endif    return NGX_CONF_OK;}static char *ngx_http_fastcgi_upstream_max_fails_unsupported(ngx_conf_t *cf,    ngx_command_t *cmd, void *conf){    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,         "\"fastcgi_upstream_max_fails\" is not supported, "         "use the \"max_fails\" parameter of the \"server\" directive ",         "inside the \"upstream\" block");    return NGX_CONF_ERROR;}static char *ngx_http_fastcgi_upstream_fail_timeout_unsupported(ngx_conf_t *cf,    ngx_command_t *cmd, void *conf){    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,         "\"fastcgi

⌨️ 快捷键说明

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