Does Nginx honor DNS TTLs for proxy upstreams?

Maxim Dounin mdounin at mdounin.ru
Thu Sep 29 07:28:33 UTC 2011


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
-------------- next part --------------
# HG changeset patch
# User Maxim Dounin <mdounin at 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) {


More information about the nginx mailing list