diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c index e976c4cdb..35638e53b 100644 --- a/src/core/ngx_inet.c +++ b/src/core/ngx_inet.c @@ -251,7 +251,7 @@ ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u) static ngx_int_t ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) { - u_char *p, *host, *port, *last, *uri; + u_char *p, *host, *port, *last, *uri, *args; size_t len; ngx_int_t n; struct hostent *h; @@ -266,6 +266,17 @@ ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) uri = ngx_strlchr(host, last, '/'); + args = ngx_strlchr(host, last, '?'); + + if (args) { + if (uri == NULL) { + uri = args; + + } else if (args < uri) { + uri = args; + } + } + if (uri) { if (u->listen || !u->uri_part) { u->err = "invalid host"; diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index f3d747f0f..83784eac7 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -536,10 +536,11 @@ static ngx_int_t ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx, ngx_http_proxy_loc_conf_t *plcf) { - size_t add; - u_short port; - ngx_str_t proxy; - ngx_url_t u; + u_char *p; + size_t add; + u_short port; + ngx_str_t proxy; + ngx_url_t u; if (ngx_http_script_run(r, &proxy, plcf->proxy_lengths->elts, 0, plcf->proxy_values->elts) @@ -589,6 +590,19 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx, return NGX_ERROR; } + if (u.uri.len && u.uri.data[0] == '?') { + p = ngx_pnalloc(r->pool, u.uri.len + 1); + if (p == NULL) { + return NGX_ERROR; + } + + *p++ = '/'; + ngx_memcpy(p, u.uri.data, u.uri.len); + + u.uri.len++; + u.uri.data = p - 1; + } + if (ngx_http_proxy_set_vars(r->pool, &u, &ctx->vars) != NGX_OK) { return NGX_ERROR; }