Nginx – How to manage down servers in a reverse proxy list with nginx

load balancingnginx

I am trying out nginx load balancing functionality.

Now the config looks like this:

...
upstream myapp1 {
    server 127.0.0.1:4000;
    server 127.0.0.1:4001;
    server 127.0.0.1:4002;
    server 127.0.0.1:4003;
   }
...

server {
    listen       80;
    server_name  mydomain.local;

    location / {
        proxy_pass   http://myapp1;
    }

Now, when I want to upgrade any of the instances, I have to stop it, update the code, and restart.

So, when the server is going down, how do I make nginx not use it in its balancing routine?

Best Answer

Once you are upgrading a server, edit the nginx configuration and add down keyword in the server line in the upstream block for the particular server.

Then issue command service nginx reload, or similar command for your distribution which makes nginx re-read its configuration. Now nginx won't use that upstream server, so you can upgrade and restart the service without any effect on users.

After that, you can remove the down keyword, and reload nginx configuration.

Related Topic