Using Weighted Round Robin Load Balancing With NGINX

When using servers with varying physical locations or differing hardware resources, you can configure NGINX to allocate more of the traffic to servers that provide less latency and can handle more of a load. This method is referred to as the weighted round-robin method.
  1. Configure weighted round robin load balancing by appending a weight value to each server entry in the configuration.

    You can configure weighted round robin configuration by appending a weight value to the end of each entry in the server group section of the NGINX site configuration file. Set the weight of the slowest server to 1, and then set the weight of other servers relative to that setting.

    The following example shows how servers can handle multiple times the load of the base server. One server receives twice the amount of traffic, while the other server receives four times the amount:

    upstream backend {
        server server1.example.com weight=1;
        server server2.example.com weight=2;
        server server3.example.com weight=4;
    }      
  2. Reload the NGINX systemd service.

    Reload NGINX to apply the new configuration:

    sudo systemctl reload nginx