How it works...

In our upstream block directive, we define the servers and the name of the backend servers. In our recipe, we simply defined these as three instances on the localhost on ports 8080, 8081, and 8082. In many scenarios, this can also be external servers (in order to horizontally balance resources).

In our server block directive, instead of connecting directly to a local application, as in the previous recipe, we connect to our upstream directive which we named localapp.

As we didn't specify an algorithm to use for load balancing, NGINX defaults to the round-robin configuration. Each of our entries is loaded in sequential order as new requests come in, unless one of the servers fails to respond.