As a freelance developer, I've stumbled upon this situation in various projects, and I want to publicly explain once and for all why the free version of nginx is not ok to use for production load balancing (LB). Here is why.
Let's first note that "health checks"(HC) are *not* available in the free version of nginx, only in the paid version. Using a LB without HC is really not ok for production, and I will now explain why.
Let's suppose you use nginx as a LB to distribute requests between 2 backends, with default parameters for the LB, typically max_fails=1 fail_timeout=10s.
Now let's suppose one of the backends becomes unresponsive. Typically nothing can connect to it, even your SSH client: trying to connect to it takes forever every time, and you eventually get a timeout somehow. This is not a fantasy, this happened to me yesterday in production. These things happen with servers. And suppose the unresponsive backend stays like this for several hours. What happens?
The LB nginx will consider the unresponsive backend as unavailable and stop sending requests to it. It will send all requests to the healthy backend only. Wait... not really! Every 10s (fail_timeout) it will test whether the unresponsive backend is "back online" by sending a *real* request (from a real user of your app) to the unresponsive backend and see how it goes. It has to use a real request for this purpose, because HC, which are the exact tool for this job, are not available in the free version of nginx.
The LB nginx will wait 60 seconds (default value of proxy_connect_timeout) before deciding that the unresponsive backend will not be available to answer the real request, and then send this request to the healthy backend and eventually answer the user. From the point of view of your user, the page will load ok (HTTP code 200 OK) but will have taken 60 seconds to load!
They are ways to improve this, and I am working on them in my current project, but frankly it is is clumsy and just a bad solution to a real problem. A good solution would be to use the paying version of Nginx which offers HC, or just to use the right tool for the job which is IMHO HAProxy.
TL;DR If you are ok with having, every 10 seconds, one user wait 60 seconds for your app to load, during the several hours when one of your backend is unresponsive, be my guest and use the free version of nginx as a load balancer in production. Otherwise don't.
Let's first note that "health checks"(HC) are *not* available in the free version of nginx, only in the paid version. Using a LB without HC is really not ok for production, and I will now explain why.
Let's suppose you use nginx as a LB to distribute requests between 2 backends, with default parameters for the LB, typically max_fails=1 fail_timeout=10s.
Now let's suppose one of the backends becomes unresponsive. Typically nothing can connect to it, even your SSH client: trying to connect to it takes forever every time, and you eventually get a timeout somehow. This is not a fantasy, this happened to me yesterday in production. These things happen with servers. And suppose the unresponsive backend stays like this for several hours. What happens?
The LB nginx will consider the unresponsive backend as unavailable and stop sending requests to it. It will send all requests to the healthy backend only. Wait... not really! Every 10s (fail_timeout) it will test whether the unresponsive backend is "back online" by sending a *real* request (from a real user of your app) to the unresponsive backend and see how it goes. It has to use a real request for this purpose, because HC, which are the exact tool for this job, are not available in the free version of nginx.
The LB nginx will wait 60 seconds (default value of proxy_connect_timeout) before deciding that the unresponsive backend will not be available to answer the real request, and then send this request to the healthy backend and eventually answer the user. From the point of view of your user, the page will load ok (HTTP code 200 OK) but will have taken 60 seconds to load!
They are ways to improve this, and I am working on them in my current project, but frankly it is is clumsy and just a bad solution to a real problem. A good solution would be to use the paying version of Nginx which offers HC, or just to use the right tool for the job which is IMHO HAProxy.
TL;DR If you are ok with having, every 10 seconds, one user wait 60 seconds for your app to load, during the several hours when one of your backend is unresponsive, be my guest and use the free version of nginx as a load balancer in production. Otherwise don't.