Multiple upstream servers
It is also possible to configure NGINX to pass the request to more than one upstream server. This is done by declaring an upstream context, defining multiple servers, and referencing the upstream in a proxy_pass
directive:
upstream app { server 127.0.0.1:9000; server 127.0.0.1:9001; server 127.0.0.1:9002; } server { location / { proxy_pass http://app; } }
Using this configuration, NGINX will pass consecutive requests in a round-robin fashion to the three upstream servers. This is useful when an application can handle only one request at a time, and you'd like NGINX to handle the client communication so that none of the application servers get overloaded. The configuration is illustrated in the following diagram:
Other load-balancing algorithms are available, as detailed in the Load-balancing algorithms section later in this chapter. Which one should be used in a particular configuration depends on the situation.
If a client should always get the...