Answer the question
In order to leave comments, you need to log in
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;
}
nginx -s reload
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question