0
0
NginxHow-ToBeginner · 3 min read

How to Mark Server as Down in Nginx Upstream Configuration

In Nginx, you can mark a server as down in the upstream block by adding the down parameter next to the server address. This tells Nginx to stop sending requests to that server without removing it from the configuration.
📐

Syntax

The down parameter is added after the server address inside the upstream block. It marks the server as unavailable for load balancing.

  • server: The backend server address (IP or hostname with port).
  • down: Marks the server as permanently down, so Nginx skips it.
nginx
upstream backend {
    server 192.168.1.10 down;
    server 192.168.1.11;
}
💻

Example

This example shows an upstream block with two servers. The first server is marked as down, so Nginx will only send traffic to the second server.

nginx
upstream backend {
    server 192.168.1.10 down;
    server 192.168.1.11;
}

server {
    listen 80;
    location / {
        proxy_pass http://backend;
    }
}
Output
When requests come to this Nginx server, they will be forwarded only to 192.168.1.11 because 192.168.1.10 is marked down and skipped.
⚠️

Common Pitfalls

Common mistakes when marking a server as down include:

  • Forgetting the down keyword, so the server still receives traffic.
  • Removing the server line instead of marking it down, which requires config reload to add it back.
  • Marking all servers as down, causing no backend to serve requests.

Always reload Nginx after changes with nginx -s reload to apply updates.

nginx
upstream backend {
    server 192.168.1.10;  # Wrong: server still active
    server 192.168.1.11;
}

# Correct way:
upstream backend {
    server 192.168.1.10 down;
    server 192.168.1.11;
}
📊

Quick Reference

DirectiveDescription
server
down;
Marks the server as unavailable for load balancing
server
;
Marks the server as active and available
nginx -s reloadReloads Nginx configuration to apply changes

Key Takeaways

Add the 'down' parameter after the server address in the upstream block to mark it as down.
Servers marked as down do not receive traffic but remain in the config for easy reactivation.
Reload Nginx after changes to apply the updated upstream configuration.
Avoid marking all servers as down to prevent service disruption.
Removing servers instead of marking them down requires config edits and reloads to restore.