Problem scenario
You have certain Nginx servers with ample resources whereas others have minimal resources. Based on geographic locations and data center bandwidth locations and costs, you want to assign fractions of the web traffic from client workstations (requests from web browsers) to different Nginx servers more than others. You do not want round-robin, equal distribution of traffic. You want customized HTTP load balancing in accord with unequal configurations. How do you distribute this traffic proportionately according to your desired specifications?
Solution
Prerequisite
You must have configured Nginx as an HTTP load balancer (or reverse proxy server). To do this, see this article which will actually work for Nginx distributing traffic to regular Nginx websites, Apache websites, or Nginx websites running in Docker containers.
Procedure
Use the "weight" keyword in the default.conf file. Even regular Docker containers on Linux severs will still support the "find" keyword. Therefore you can always use "find / -name default.conf" to find the Nginx configuration file. This file should have an "upstream backend {}" section. Here is an example:
upstream backend {
server 10.10.10.10 weight=5;
server 10.10.10.11 weight=4;
server 10.10.10.12 weight=2;
server 10.10.10.13 weight=4;
}
The higher the weight, the greater the traffic that is sent to the server. In this instance the 10.10.10.12 server would receive half the traffic that server 10.10.10.13 would receive. This weight directive works the same for Nginx instances running directly on a server or running in a Docker container. The default weight is 1 (according to DigitalOcean's website). The percentage of traffic a server will get will be its individual weight divided by the sum of all the weights of the servers in the "upstream backend {}" section.
The "weight" values with Nginx in Docker behave no differently from Ngnix running on a server directly.