2
votes

When configuring NGINX with multiple server entries, one can configure a round-robin algorithm for distributing load. NGINX offers the weight to indicate how weight is distributed. For ex.:

upstream backend {
 server backend1.example.com       weight=5;
 server backend2.example.com:8080  weight=1;

}
server {
    location / {
        proxy_pass http://backend;
    }
}

Question is: What is the maximum value assignable to weight?

My problem is that I have encountered a configuration with 2 server entries one with a weight value of 2000000000 (2 billion) and one with a value of 1. The intention was to have all traffic directed on the first server as temporarily the second one was down. However after far less than 2 bil requests users got error because they were directed to the second server.

1
Looking at the NGINX source code it seems that weight is of type ngx_int_t (github.com/nginx/nginx/blob/…), so I'm assuming that means an int - coding-dude.com

1 Answers

1
votes

You should use health checking for that usage, not weight.

You have 2 options:

  1. Using built in nginx layer 3 healthchecks:

    Using max_fails, fail_timeout and even backup directive.

    backup: marks the server as a backup server. It will be passed requests when the primary servers are unavailable.

  2. Using community modules like nginx_upstream_check_module

    This module enables layer 7 healthchecks, This is the recommended way.