diff src/http/ngx_http_upstream.c @ 212:56688ed172c8 NGINX_0_3_53

nginx 0.3.53 *) Change: the "add_header" directive adds the string to 204, 301, and 302 responses. *) Feature: the "server" directive in the "upstream" context supports the "weight" parameter. *) Feature: the "server_name" directive supports the "*" wildcard. *) Feature: nginx supports the request body size more than 2G. *) Bugfix: if a client was successfully authorized using "satisfy_any on", then anyway the message "access forbidden by rule" was written in the log. *) Bugfix: the "PUT" method may erroneously not create a file and return the 409 code. *) Bugfix: if the IMAP/POP3 backend returned an error, then nginx continued proxying anyway.
author Igor Sysoev <http://sysoev.ru>
date Fri, 07 Jul 2006 00:00:00 +0400
parents b12b3b1a9426
children 0ad9eeb6ac7f
line wrap: on
line diff
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -226,7 +226,7 @@ static ngx_command_t  ngx_http_upstream_
       NULL },
 
     { ngx_string("server"),
-      NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
+      NGX_HTTP_UPS_CONF|NGX_CONF_TAKE12,
       ngx_http_upstream_server,
       NGX_HTTP_SRV_CONF_OFFSET,
       0,
@@ -2729,7 +2729,6 @@ ngx_http_upstream(ngx_conf_t *cf, ngx_co
     }
 
     uscf->peers->number = n;
-    uscf->peers->weight = 1;
 
     n = 0;
 
@@ -2750,6 +2749,8 @@ ngx_http_upstream_server(ngx_conf_t *cf,
 
     ngx_str_t                    *value;
     ngx_url_t                     u;
+    ngx_int_t                     weight;
+    ngx_uint_t                    i;
     ngx_peers_t                 **peers;
 
     if (uscf->servers == NULL) {
@@ -2780,9 +2781,41 @@ ngx_http_upstream_server(ngx_conf_t *cf,
         return NGX_CONF_ERROR;
     }
 
+    weight = 1;
+
+    if (cf->args->nelts == 3) {
+
+        value = &value[2];
+
+        if (ngx_strncmp(value->data, "weight=", 7) == 0) {
+
+            weight = ngx_atoi(&value->data[7], value->len - 7);
+
+            if (weight == NGX_ERROR || weight == 0) {
+                goto invalid;
+            }
+
+        } else {
+            goto invalid;
+        }
+    }
+
+    for (i = 0; i < u.peers->number; i++) {
+        u.peers->peer[i].weight = weight;
+        u.peers->peer[i].current_weight = weight;
+        u.peers->peer[i].max_fails = NGX_CONF_UNSET_UINT;
+        u.peers->peer[i].fail_timeout = NGX_CONF_UNSET;
+    }
+
     *peers = u.peers;
 
     return NGX_CONF_OK;
+
+invalid:
+
+    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"", value);
+
+    return NGX_CONF_ERROR;
 }
 
 
@@ -2893,8 +2926,7 @@ ngx_http_upstream_init_main_conf(ngx_con
         }
 
         uscfp[i]->peers = ngx_inet_resolve_peer(cf, &uscfp[i]->host,
-                          uscfp[i]->port);
-
+                                                uscfp[i]->port);
         if (uscfp[i]->peers == NULL) {
             return NGX_CONF_ERROR;
         }
@@ -2908,6 +2940,7 @@ ngx_http_upstream_init_main_conf(ngx_con
         }
     }
 
+
     if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t))
         != NGX_OK)
     {