nginx如何下掉server中某个节点

In Nginx, the weight parameter must be an integer of 1 or higher. It represents the proportion of traffic a server receives, so setting it to 0 mathematically breaks the load-balancing calculation.


1.You want to temporarily disable that server

If your goal is to stop traffic from going to 10.6.234.165:10001 without deleting the line, use the down parameter instead.

Change line 3 to this:

1
server 10.6.234.165:10001 down;  # 等价注释

2.You want it to only handle traffic when other servers fail

If you want it to act as a backup/wrapper, use the backup parameter.

Change line 3 to this:

1
server 10.6.234.165:10001 backup;  # 调度或者请求失败则请求backup节点

3.You just want it to have the lowest standard priority

If you want it to receive the absolute minimum amount of traffic compared to your other servers (which are set to 100), change the weight to 1.

Change line 3 to this:

1
server 10.6.234.165:10001 weight=1;  # weight 1~100

What to do next:

  1. Open the file: vim /local/base/tengine/conf.d/ocrserver.conf
  2. Update line 3 using one of the methods above (most likely down; if you were trying to set it to 0).
  3. Test the configuration again: nginx -t
  4. If it passes, reload Nginx: nginx -s reload