Using Least-Connected Load Balancing With NGINX

The least-connected load balancing method is used to automatically control the load on application instances, mostly in situations where different inbound requests might take longer to process than other requests.

If you're using the least-connected load balancing method, NGINX always directs new incoming requests to the server with the least number of active requests. This load balancing strategy is intended to ensure that no busy servers are overloaded with new requests, while other servers that can handle the load remain idle.

  1. Configure least-connected load balancing by adding the least-conn directive to the server group configuration.

    You can activate the least-connected load balancing method for NGINX by specifying the least-conn directive as part of the server group configuration, for example:

    upstream backend {
        least_conn;
        server server1.example.com;
        server server2.example.com;
        server server3.example.com;
    }
  2. Reload the NGINX systemd service.

    Reload NGINX to apply the new configuration:

    sudo systemctl reload nginx