M
M
Mika Slepinin2016-11-21 11:12:21
Nginx
Mika Slepinin, 2016-11-21 11:12:21

Nginx - how to disable and enable one of the servers in upstream?

Good afternoon.
There was such a task: turn on and off one of the servers in upstream Nginx'a on command, or in some other way. Now this is simply done by adding a "#" character in front of one of the upstream servers. Like this:

upstream backend {
#    server 192.168.12.1;
    server 192.168.12.2;
}

And by restarting Nginx:
nginx -s reload
Is there any way to do this easier without getting into the config, without adding and removing the "#" character?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Nemiro, 2016-11-21
@AlekseyNemiro

Make two configuration files and swap them when necessary :-) Disable the first, enable the second and vice versa.
Or use the include directive .
The process can be automated. Including the option with comments (although it will be difficult with comments, you can find an easier option). I think you can just make a config file template with a text marker instead of server or server address, replace that marker with the desired value (like: sed -i.bak s/anymarker/192.168.12.2/g example.conf ) and then replace the config file.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question