]> git.kaiwu.me - nginx.git/commitdiff
Upstream: fixed "no port" detection in evaluated upstreams.
authorRuslan Ermilov <ru@nginx.com>
Sat, 21 Nov 2015 07:44:07 +0000 (10:44 +0300)
committerRuslan Ermilov <ru@nginx.com>
Sat, 21 Nov 2015 07:44:07 +0000 (10:44 +0300)
If an upstream with variables evaluated to address without a port,
then instead of a "no port in upstream" error an attempt was made
to connect() which failed with EADDRNOTAVAIL.

src/http/modules/ngx_http_fastcgi_module.c
src/http/modules/ngx_http_proxy_module.c
src/http/modules/ngx_http_scgi_module.c
src/http/modules/ngx_http_uwsgi_module.c
src/http/ngx_http_upstream.c

index 668719fe503832653347ae0f5bebcbfa4abebf70..dbd7767f0608508b29049a89f90a04b2ad7f1f2a 100644 (file)
@@ -773,10 +773,11 @@ ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
 
     } else {
         u->resolved->host = url.host;
-        u->resolved->port = url.port;
-        u->resolved->no_port = url.no_port;
     }
 
+    u->resolved->port = url.port;
+    u->resolved->no_port = url.no_port;
+
     return NGX_OK;
 }
 
index 1933509143ab932211ca656abebea52d81f59c5d..e9224e24d42e9b0f38668301a5f312a86174c707 100644 (file)
@@ -1015,10 +1015,11 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
 
     } else {
         u->resolved->host = url.host;
-        u->resolved->port = (in_port_t) (url.no_port ? port : url.port);
-        u->resolved->no_port = url.no_port;
     }
 
+    u->resolved->port = (in_port_t) (url.no_port ? port : url.port);
+    u->resolved->no_port = url.no_port;
+
     return NGX_OK;
 }
 
index 6e5b0770cc20ab462402dc2a7862e7305183615b..76c77863c6c427e595852572ca28db0396a5d454 100644 (file)
@@ -569,10 +569,11 @@ ngx_http_scgi_eval(ngx_http_request_t *r, ngx_http_scgi_loc_conf_t * scf)
 
     } else {
         u->resolved->host = url.host;
-        u->resolved->port = url.port;
-        u->resolved->no_port = url.no_port;
     }
 
+    u->resolved->port = url.port;
+    u->resolved->no_port = url.no_port;
+
     return NGX_OK;
 }
 
index a50c5532072f6174bb3ecdf47c07350920e65242..0313dfa555714989eb45bc5188b96b02d6371063 100644 (file)
@@ -771,10 +771,11 @@ ngx_http_uwsgi_eval(ngx_http_request_t *r, ngx_http_uwsgi_loc_conf_t * uwcf)
 
     } else {
         u->resolved->host = url.host;
-        u->resolved->port = url.port;
-        u->resolved->no_port = url.no_port;
     }
 
+    u->resolved->port = url.port;
+    u->resolved->no_port = url.no_port;
+
     return NGX_OK;
 }
 
index 74fffd5c847aa46b961e487c7c275d76bc65b08b..8a9fbac465de73eb57f15ffad07310353f137bd4 100644 (file)
@@ -633,8 +633,18 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
         u->ssl_name = u->resolved->host;
 #endif
 
+        host = &u->resolved->host;
+
         if (u->resolved->sockaddr) {
 
+            if (u->resolved->port == 0) {
+                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+                              "no port in upstream \"%V\"", host);
+                ngx_http_upstream_finalize_request(r, u,
+                                                   NGX_HTTP_INTERNAL_SERVER_ERROR);
+                return;
+            }
+
             if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)
                 != NGX_OK)
             {
@@ -648,8 +658,6 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
             return;
         }
 
-        host = &u->resolved->host;
-
         umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
 
         uscfp = umcf->upstreams.elts;