static char * ngx_http_tnt_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_tnt_loc_conf_t *mlcf = conf; ngx_str_t *value; ngx_url_t u; ngx_http_core_loc_conf_t *clcf; if (mlcf->upstream.upstream) { return "is duplicate"; } value = cf->args->elts; ngx_memzero(&u, sizeof(ngx_url_t)); u.url = value[1]; u.no_resolve = 1; mlcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); if (mlcf->upstream.upstream == NULL) { return NGX_CONF_ERROR; } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_tnt_handler; if (clcf->name.data[clcf->name.len - 1] == '/') { clcf->auto_redirect = 1; } return NGX_CONF_OK; }
static char * ngx_http_drizzle_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_drizzle_loc_conf_t *dlcf = conf; ngx_http_core_loc_conf_t *clcf; ngx_str_t *value; ngx_http_compile_complex_value_t ccv; ngx_url_t url; ngx_uint_t n; if (dlcf->upstream.upstream) { return "is duplicate"; } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_drizzle_handler; if (clcf->name.data[clcf->name.len - 1] == '/') { clcf->auto_redirect = 1; } value = cf->args->elts; n = ngx_http_script_variables_count(&value[1]); if (n) { dlcf->complex_target = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); if (dlcf->complex_target == NULL) { return NGX_CONF_ERROR; } ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); ccv.cf = cf; ccv.value = &value[1]; ccv.complex_value = dlcf->complex_target; if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { return NGX_CONF_ERROR; } return NGX_CONF_OK; } dlcf->complex_target = NULL; ngx_memzero(&url, sizeof(ngx_url_t)); url.url = value[1]; url.no_resolve = 1; dlcf->upstream.upstream = ngx_http_upstream_add(cf, &url, 0); if (dlcf->upstream.upstream == NULL) { return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char * ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_scgi_loc_conf_t *scf = conf; ngx_url_t u; ngx_str_t *value, *url; ngx_uint_t n; ngx_http_core_loc_conf_t *clcf; ngx_http_script_compile_t sc; if (scf->upstream.upstream || scf->scgi_lengths) { return "is duplicate"; } clcf = ngx_http_conf_get_module_loc_conf (cf, ngx_http_core_module); clcf->handler = ngx_http_scgi_handler; value = cf->args->elts; url = &value[1]; n = ngx_http_script_variables_count(url); if (n) { ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); sc.cf = cf; sc.source = url; sc.lengths = &scf->scgi_lengths; sc.values = &scf->scgi_values; sc.variables = n; sc.complete_lengths = 1; sc.complete_values = 1; if (ngx_http_script_compile(&sc) != NGX_OK) { return NGX_CONF_ERROR; } return NGX_CONF_OK; } ngx_memzero(&u, sizeof(ngx_url_t)); u.url = value[1]; u.no_resolve = 1; scf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); if (scf->upstream.upstream == NULL) { return NGX_CONF_ERROR; } if (clcf->name.data[clcf->name.len - 1] == '/') { clcf->auto_redirect = 1; } return NGX_CONF_OK; }
static char * ngx_http_poller_set_endpoint(ngx_conf_t *cf, ngx_http_poller_t *poller, ngx_str_t *value) { size_t add; u_short port; if (poller->endpoint.data != NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "[poller] %V: endpoint already declared", &poller->name); return NGX_CONF_ERROR; } poller->endpoint = *value; /* parse the scheme */ if (poller->endpoint.len > 7 && ngx_strncmp(poller->endpoint.data, "http://", 7) == 0) { add = 7; port = 80; } else if (poller->endpoint.len > 8 && ngx_strncmp(poller->endpoint.data, "https://", 8) == 0) { #if NGX_HTTP_SSL add = 8; port = 443; if (ngx_http_poller_set_ssl(cf, poller) != NGX_OK) { return NGX_CONF_ERROR; } #else /* !NGX_HTTP_SSL */ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "[poller] %V: endpoint %V: requires SSL support", &poller->name, &poller->endpoint); return NGX_CONF_ERROR; #endif /* NGX_HTTP_SSL */ } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "[poller] %V: endpoint %V: invalid scheme", &poller->name, &poller->endpoint); return NGX_CONF_ERROR; } poller->scheme.len = add; poller->scheme.data = poller->endpoint.data; poller->url.url.len = poller->endpoint.len - add; poller->url.url.data = poller->endpoint.data + add; poller->url.default_port = port; poller->url.uri_part = 1; poller->url.no_resolve = 1; poller->upstream.upstream = ngx_http_upstream_add(cf, &poller->url, 0); if (poller->upstream.upstream == NULL) { return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char * ngx_http_beanstalkd_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_beanstalkd_loc_conf_t *blcf = conf; ngx_str_t *value; ngx_http_core_loc_conf_t *clcf; ngx_uint_t n; ngx_url_t url; ngx_http_compile_complex_value_t ccv; if (blcf->upstream.upstream || blcf->complex_target) { return "is duplicate"; } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_beanstalkd_handler; value = cf->args->elts; n = ngx_http_script_variables_count(&value[1]); if (n) { blcf->complex_target = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); if (blcf->complex_target == NULL) { return NGX_CONF_ERROR; } ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); ccv.cf = cf; ccv.value = &value[1]; ccv.complex_value = blcf->complex_target; if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { return NGX_CONF_ERROR; } return NGX_CONF_OK; } blcf->complex_target = NULL; ngx_memzero(&url, sizeof(ngx_url_t)); url.url = value[1]; url.no_resolve = 1; blcf->upstream.upstream = ngx_http_upstream_add(cf, &url, 0); if (blcf->upstream.upstream == NULL) { return NGX_CONF_ERROR; } return NGX_CONF_OK; }
/* Process the configuration directive "mobwrite_pass host:port" */ static char * ngx_http_mobwrite_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_str_t *args; ngx_url_t url; ngx_http_core_loc_conf_t *core_loc_conf; ngx_http_mobwrite_loc_conf_t *mobwrite_conf = (ngx_http_mobwrite_loc_conf_t *)conf; args = cf->args->elts; url.url = args[1]; url.default_port = 3017; url.uri_part = 1; url.no_resolve = 1; mobwrite_conf->upstream.upstream = ngx_http_upstream_add(cf, &url, 0); core_loc_conf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); core_loc_conf->handler = ngx_http_mobwrite_handler; return NGX_CONF_OK; }
static char * passenger_enabled(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { passenger_loc_conf_t *lcf = conf; ngx_url_t u; ngx_http_core_loc_conf_t *clcf; ngx_str_t *value; value = cf->args->elts; if (ngx_strcasecmp(value[1].data, (u_char *) "on") == 0) { #if NGINX_VERSION_NUM < 7000 if (lcf->upstream.schema.len) { return "is duplicate"; } #endif lcf->enabled = 1; ngx_memzero(&u, sizeof(ngx_url_t)); u.url.data = (u_char *) passenger_helper_server_socket; u.url.len = strlen(passenger_helper_server_socket); u.no_resolve = 1; lcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); if (lcf->upstream.upstream == NULL) { return NGX_CONF_ERROR; } #if NGINX_VERSION_NUM < 7000 lcf->upstream.schema = passenger_schema_string; #endif clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = passenger_content_handler; if (clcf->name.data != NULL && clcf->name.data[clcf->name.len - 1] == '/') { clcf->auto_redirect = 1; } } else { lcf->enabled = 0; } return NGX_CONF_OK; }
static char * passenger_enabled(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { passenger_loc_conf_t *passenger_conf = conf; ngx_http_core_loc_conf_t *clcf; ngx_str_t *value; ngx_url_t upstream_url; value = cf->args->elts; if (ngx_strcasecmp(value[1].data, (u_char *) "on") == 0) { passenger_conf->enabled = 1; /* Register a placeholder value as upstream address. The real upstream * address (the helper agent socket filename) will be set while processing * requests, because we can't start the helper agent until config * loading is done. */ ngx_memzero(&upstream_url, sizeof(ngx_url_t)); upstream_url.url = pp_placeholder_upstream_address; upstream_url.no_resolve = 1; passenger_conf->upstream_config.upstream = ngx_http_upstream_add(cf, &upstream_url, 0); if (passenger_conf->upstream_config.upstream == NULL) { return NGX_CONF_ERROR; } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = passenger_content_handler; if (clcf->name.data != NULL && clcf->name.data[clcf->name.len - 1] == '/') { clcf->auto_redirect = 1; } } else if (ngx_strcasecmp(value[1].data, (u_char *) "off") == 0) { passenger_conf->enabled = 0; } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "\"passenger_enabled\" must be either set to \"on\" " "or \"off\""); return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char * ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_memcached_loc_conf_t *lcf = conf; ngx_str_t *value; ngx_url_t u; 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("memcached://") - 1; lcf->upstream.schema.data = (u_char *) "memcached://"; clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_memcached_handler; if (clcf->name.data[clcf->name.len - 1] == '/') { clcf->auto_redirect = 1; } lcf->index = ngx_http_get_variable_index(cf, &ngx_http_memcached_key); if (lcf->index == NGX_ERROR) { return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char* ngx_conf_mcset_set_pass( ngx_conf_t *cf, ngx_command_t *cmd, void *conf ) { ngx_str_t *value; ngx_url_t u; ngx_http_mcset_module_conf_t* mscf; mscf = conf; if ( mscf->upstream.upstream ) { return "is duplicate"; } value = cf->args->elts; ngx_memzero( &u, sizeof( ngx_url_t ) ); u.url = value[1]; u.no_resolve = 1; mscf->upstream.upstream = ngx_http_upstream_add( cf, &u, 0 ); if ( mscf->upstream.upstream == NULL ) { return NGX_CONF_ERROR; } mscf->key_index = ngx_http_get_variable_index( cf, &ngx_mcset_key ); if ( mscf->key_index == NGX_ERROR ) { return NGX_CONF_ERROR; } mscf->val_index = ngx_http_get_variable_index( cf, &ngx_mcset_val ); if ( mscf->val_index == NGX_ERROR ) { return NGX_CONF_ERROR; } mscf->op_index = ngx_http_get_variable_index( cf, &ngx_mcset_op ); if ( mscf->op_index == NGX_ERROR ) { return NGX_CONF_ERROR; } return NGX_CONF_OK; }
static char * ngx_http_memcached_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_memcached_loc_conf_t *mlcf; ngx_http_core_loc_conf_t *clcf; ngx_str_t *value; ngx_url_t url; mlcf = conf; if (mlcf->upstream.upstream) return "is duplicate"; value = cf->args->elts; ngx_memzero(&url, sizeof(ngx_url_t)); url.url = value[1]; url.no_resolve = 1; if (!(mlcf->upstream.upstream = ngx_http_upstream_add(cf, &url, 0))) return NGX_CONF_ERROR; clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_memcached_handler; if (clcf->name.data[clcf->name.len - 1] == '/') clcf->auto_redirect = 1; /* define customer variable */ if (NGX_ERROR == (mlcf->key = ngx_http_get_variable_index(cf, &ngx_http_memcached_key))) return NGX_CONF_ERROR; if (NGX_ERROR == (mlcf->flags = ngx_http_get_variable_index(cf, &ngx_http_memcached_flags))) return NGX_CONF_ERROR; if (NGX_ERROR == (mlcf->exptime = ngx_http_get_variable_index(cf, &ngx_http_memcached_exptime))) return NGX_CONF_ERROR; if (NGX_ERROR == (mlcf->unique = ngx_http_get_variable_index(cf, &ngx_http_memcached_unique))) return NGX_CONF_ERROR; return NGX_CONF_OK; }
static char * ngx_http_session_sticky_hide_cookie(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_http_ss_loc_conf_t *slcf = conf; size_t add; ngx_str_t *value; ngx_url_t u; value = (ngx_str_t *) cf->args->elts; if (ngx_strncmp(value[0].data, "session_sticky_header", 21) == 0) { ngx_conf_deprecated(cf, &ngx_conf_deprecated_session_sticky_header, NULL); } if (ngx_strncmp(value[1].data, "upstream=", 9) == 0) { add = 9; ngx_memzero(&u, sizeof(ngx_url_t)); u.url.len = value[1].len - add; u.url.data = value[1].data + add; u.uri_part = 1; u.no_resolve = 1; slcf->uscf = ngx_http_upstream_add(cf, &u, 0); if (slcf->uscf == NULL) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid upstream name"); return NGX_CONF_ERROR; } return NGX_CONF_OK; } ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid argument of \"%V\"", &value[1]); return NGX_CONF_ERROR; }
/* echo 指令的处理,主要是进行handler的注册 */ static char* ngx_conf_set_echo(ngx_conf_t *cf, ngx_command_t *cmd, void* conf) { ngx_http_core_loc_conf_t* clcf; ngx_str_t *value; ngx_url_t u; ngx_http_echov4_loc_conf_t* elcf = (ngx_http_echov4_loc_conf_t*) conf; ngx_log_debug0(NGX_LOG_DEBUG_HTTP, cf->log, 0, "ngx_conf_set_echo called - [rainx]"); clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_http_echo_handler; value = cf->args->elts; u.url = value[1]; u.no_resolve = 1; elcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); if (elcf->upstream.upstream == NULL){ return NGX_CONF_ERROR; } return NGX_CONF_OK; }
char * ngx_postgres_conf_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_str_t *value = cf->args->elts; ngx_postgres_loc_conf_t *pglcf = conf; ngx_http_core_loc_conf_t *clcf; ngx_http_compile_complex_value_t ccv; ngx_url_t url; dd("entering"); if ((pglcf->upstream.upstream != NULL) || (pglcf->upstream_cv != NULL)) { dd("returning"); return "is duplicate"; } if (value[1].len == 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "postgres: empty upstream in \"%V\" directive", &cmd->name); dd("returning NGX_CONF_ERROR"); return NGX_CONF_ERROR; } clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); clcf->handler = ngx_postgres_handler; if (clcf->name.data[clcf->name.len - 1] == '/') { clcf->auto_redirect = 1; } if (ngx_http_script_variables_count(&value[1])) { /* complex value */ dd("complex value"); pglcf->upstream_cv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); if (pglcf->upstream_cv == NULL) { dd("returning NGX_CONF_ERROR"); return NGX_CONF_ERROR; } ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); ccv.cf = cf; ccv.value = &value[1]; ccv.complex_value = pglcf->upstream_cv; if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { dd("returning NGX_CONF_ERROR"); return NGX_CONF_ERROR; } dd("returning NGX_CONF_OK"); return NGX_CONF_OK; } else { /* simple value */ dd("simple value"); ngx_memzero(&url, sizeof(ngx_url_t)); url.url = value[1]; url.no_resolve = 1; pglcf->upstream.upstream = ngx_http_upstream_add(cf, &url, 0); if (pglcf->upstream.upstream == NULL) { dd("returning NGX_CONF_ERROR"); return NGX_CONF_ERROR; } dd("returning NGX_CONF_OK"); return NGX_CONF_OK; } }
static char * ngx_http_tcp_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) { ngx_uint_t n = 0; ngx_str_t *value = NULL, *url = NULL; ngx_str_t upstream_name; ngx_url_t u; ngx_http_script_compile_t sc; ngx_http_tcp_proxy_loc_conf_t *tlcf = conf; if (tlcf->upstream.upstream || tlcf->proxy_lengths) { return "is duplicate"; } if (cf->args->nelts > 2){ return "input param format wrong"; } ngx_str_set(&upstream_name, "tcp"); if (ngx_http_proxy_switch_set_upstream_instance(cf, &tlcf->upstream, &upstream_name) != NGX_OK){ return "upstream not support"; } if (cf->args->nelts == 1){ if (!ngx_http_conf_dyconfig_enabled(cf)){ return "dyconfig not configured yet."; } if(ngx_http_proxy_switch_set_proxy_instance(cf, &ngx_http_tcp_proxy) != NGX_OK){ return NGX_CONF_ERROR; } return NGX_CONF_OK; } value = cf->args->elts; url = &value[1]; n = ngx_http_script_variables_count(url); if (n) { ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); sc.cf = cf; sc.source = url; sc.lengths = &tlcf->proxy_lengths; sc.values = &tlcf->proxy_values; sc.variables = n; sc.complete_lengths = 1; sc.complete_values = 1; if (ngx_http_script_compile(&sc) != NGX_OK) { return NGX_CONF_ERROR; } }else{ ngx_memzero(&u, sizeof(ngx_url_t)); u.url = *url; u.no_resolve = 1; tlcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0); if (tlcf->upstream.upstream == NULL) { return NGX_CONF_ERROR; } } if(ngx_http_proxy_switch_set_proxy_instance(cf, &ngx_http_tcp_proxy) != NGX_OK){ return NGX_CONF_ERROR; } return NGX_CONF_OK; }