Welcome! Log In Create A New Profile

Advanced

Re: Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin
September 29, 2011 03:30AM
Hello!

On Wed, Sep 28, 2011 at 03:35:50PM -0400, csg wrote:

> Maxim Dounin Wrote:
> -------------------------------------------------------
> Hello again!
>
> > .... and $backend won't be set as a result.
> > Moving "set" before
> > "rewrite .. break" will do the trick.
>
> Right, in this case the $backend applies to proxy_pass and the request
> gets proxied but unfortunatelly in this case the rewrite rule does not
> have effect anymore. It still gets applied according to the error logs,
> but instead of the rewritten URL path to original one gets proxied. To
> make it more clear I changed the example configuration I posted above by
> having each virtual host its own access and error log.

This looks like a bug (or at least misfeature). Please try the
attached patch.

Maxim Dounin
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1317281138 -14400
# Node ID d6a0787307868c06073d92bb39eb2f73acf19d7c
# Parent 29d417d419d946dce33023c71cce0e586ef3547b
Proxy: made proxy_pass with variables more consitent.

If proxy_pass were used with variables and there were no URI component,
nginx always used unparsed URI. This isn't consistent with "no variables"
case, where e.g. rewrites are applied even if there are no URI component.

Fix is to use same logic in both cases, i.e. only use unparsed URI if
it's valid and request is main one.

diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -738,9 +738,6 @@ ngx_http_proxy_eval(ngx_http_request_t *
url.uri.len++;
url.uri.data = p - 1;
}
-
- } else {
- url.uri = r->unparsed_uri;
}

ctx->vars.key_start = u->schema;
@@ -808,7 +805,7 @@ ngx_http_proxy_create_key(ngx_http_reque
return NGX_ERROR;
}

- if (plcf->proxy_lengths) {
+ if (plcf->proxy_lengths && ctx->vars.uri.len) {

*key = ctx->vars.uri;
u->uri = ctx->vars.uri;
@@ -918,7 +915,7 @@ ngx_http_proxy_create_request(ngx_http_r
loc_len = 0;
unparsed_uri = 0;

- if (plcf->proxy_lengths) {
+ if (plcf->proxy_lengths && ctx->vars.uri.len) {
uri_len = ctx->vars.uri.len;

} else if (ctx->vars.uri.len == 0 && r->valid_unparsed_uri && r == r->main)
@@ -1024,7 +1021,7 @@ ngx_http_proxy_create_request(ngx_http_r

u->uri.data = b->last;

- if (plcf->proxy_lengths) {
+ if (plcf->proxy_lengths && ctx->vars.uri.len) {
b->last = ngx_copy(b->last, ctx->vars.uri.data, ctx->vars.uri.len);

} else if (unparsed_uri) {
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Does Nginx honor DNS TTLs for proxy upstreams?

csg September 26, 2011 04:42AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin September 26, 2011 05:38AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 26, 2011 09:40AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin September 26, 2011 09:58AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 28, 2011 12:05PM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin September 28, 2011 12:14PM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 28, 2011 03:35PM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 29, 2011 03:31AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 29, 2011 03:32AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg September 29, 2011 03:53AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin September 29, 2011 03:30AM

Re: Does Nginx honor DNS TTLs for proxy upstreams?

csg October 04, 2011 04:12AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 85
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready