static char *
ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_http_proxy_loc_conf_t *plcf = conf;
    size_t                      add;
    u_short                     port;
    ngx_str_t                  *value, *url;
    ngx_url_t                   u;
    ngx_uint_t                  n;
    ngx_http_core_loc_conf_t   *clcf;
    ngx_http_script_compile_t   sc;
    if (plcf->upstream.upstream || plcf->proxy_lengths) {
        return "is duplicate";
    }
    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
    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 = &plcf->proxy_lengths;
        sc.values = &plcf->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;
        }
#if (NGX_HTTP_SSL)
        if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) {
            return NGX_CONF_ERROR;
        }
#endif
        clcf->handler = ngx_http_proxy_handler;
        return NGX_CONF_OK;
    }
    if (ngx_strncasecmp(url->data, (u_char *) "http://", 7) == 0) {
        add = 7;
        port = 80;
    } else if (ngx_strncasecmp(url->data, (u_char *) "https://", 8) == 0) {
#if (NGX_HTTP_SSL)
        if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) {
            return NGX_CONF_ERROR;
        }
        add = 8;
        port = 443;
#else
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                           "https protocol requires SSL support");
        return NGX_CONF_ERROR;
#endif
    } else {
        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix");
        return NGX_CONF_ERROR;
    }
    ngx_memzero(&u, sizeof(ngx_url_t));
    u.url.len = url->len - add;
    u.url.data = url->data + add;
    u.default_port = port;
    u.uri_part = 1;
    u.no_resolve = 1;
    plcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
    if (plcf->upstream.upstream == NULL) {
        return NGX_CONF_ERROR;
    }
    plcf->vars.schema.len = add;
    plcf->vars.schema.data = url->data;
    plcf->vars.key_start = plcf->vars.schema;
    ngx_http_proxy_set_vars(&u, &plcf->vars);
    clcf->handler = ngx_http_proxy_handler;
    plcf->location = clcf->name;
    if (clcf->named
#if (NGX_PCRE)
        || clcf->regex
#endif
        || clcf->noname)
    {
        if (plcf->vars.uri.len) {
            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                               "\"proxy_pass\" may not have URI part in "
                               "location given by regular expression, "
                               "or inside named location, "
                               "or inside the \"if\" statement, "
                               "or inside the \"limit_except\" block");
            return NGX_CONF_ERROR;
        }
        plcf->location.len = 0;
    }
    plcf->url = *url;
    if (clcf->name.data[clcf->name.len - 1] == '/') {
        clcf->auto_redirect = 1;
    }
    return NGX_CONF_OK;
}
['static char *\nngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)\n{\n    ngx_http_proxy_loc_conf_t *plcf = conf;\n    size_t                      add;\n    u_short                     port;\n    ngx_str_t                  *value, *url;\n    ngx_url_t                   u;\n    ngx_uint_t                  n;\n    ngx_http_core_loc_conf_t   *clcf;\n    ngx_http_script_compile_t   sc;\n    if (plcf->upstream.upstream || plcf->proxy_lengths) {\n        return "is duplicate";\n    }\n    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);\n    value = cf->args->elts;\n    url = &value[1];\n    n = ngx_http_script_variables_count(url);\n    if (n) {\n        ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));\n        sc.cf = cf;\n        sc.source = url;\n        sc.lengths = &plcf->proxy_lengths;\n        sc.values = &plcf->proxy_values;\n        sc.variables = n;\n        sc.complete_lengths = 1;\n        sc.complete_values = 1;\n        if (ngx_http_script_compile(&sc) != NGX_OK) {\n            return NGX_CONF_ERROR;\n        }\n#if (NGX_HTTP_SSL)\n        if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) {\n            return NGX_CONF_ERROR;\n        }\n#endif\n        clcf->handler = ngx_http_proxy_handler;\n        return NGX_CONF_OK;\n    }\n    if (ngx_strncasecmp(url->data, (u_char *) "http://", 7) == 0) {\n        add = 7;\n        port = 80;\n    } else if (ngx_strncasecmp(url->data, (u_char *) "https://", 8) == 0) {\n#if (NGX_HTTP_SSL)\n        if (ngx_http_proxy_set_ssl(cf, plcf) != NGX_OK) {\n            return NGX_CONF_ERROR;\n        }\n        add = 8;\n        port = 443;\n#else\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                           "https protocol requires SSL support");\n        return NGX_CONF_ERROR;\n#endif\n    } else {\n        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid URL prefix");\n        return NGX_CONF_ERROR;\n    }\n    ngx_memzero(&u, sizeof(ngx_url_t));\n    u.url.len = url->len - add;\n    u.url.data = url->data + add;\n    u.default_port = port;\n    u.uri_part = 1;\n    u.no_resolve = 1;\n    plcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);\n    if (plcf->upstream.upstream == NULL) {\n        return NGX_CONF_ERROR;\n    }\n    plcf->vars.schema.len = add;\n    plcf->vars.schema.data = url->data;\n    plcf->vars.key_start = plcf->vars.schema;\n    ngx_http_proxy_set_vars(&u, &plcf->vars);\n    clcf->handler = ngx_http_proxy_handler;\n    plcf->location = clcf->name;\n    if (clcf->named\n#if (NGX_PCRE)\n        || clcf->regex\n#endif\n        || clcf->noname)\n    {\n        if (plcf->vars.uri.len) {\n            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,\n                               "\\"proxy_pass\\" may not have URI part in "\n                               "location given by regular expression, "\n                               "or inside named location, "\n                               "or inside the \\"if\\" statement, "\n                               "or inside the \\"limit_except\\" block");\n            return NGX_CONF_ERROR;\n        }\n        plcf->location.len = 0;\n    }\n    plcf->url = *url;\n    if (clcf->name.data[clcf->name.len - 1] == \'/\') {\n        clcf->auto_redirect = 1;\n    }\n    return NGX_CONF_OK;\n}', "ngx_uint_t\nngx_http_script_variables_count(ngx_str_t *value)\n{\n    ngx_uint_t  i, n;\n    for (n = 0, i = 0; i < value->len; i++) {\n        if (value->data[i] == '$') {\n            n++;\n        }\n    }\n    return n;\n}"]