How do I remove a backend instance with zero downtime?
Mark the server as 'down' in the upstream block: server 127.0.0.1:3001 down;. Reload Nginx (stops sending new requests to it). Wait for existing requests to finish. Stop the instance (pm2 stop). Remove the line from config and reload again.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Nginx Load Balancing Updates Adding and Removing Backend Instances
Add a new line to the upstream block: server 127.0.0.1:3001;. Start the Node.js instance on that port (PORT=3001 pm2 start src/server.js). Test with nginx -t and reload. Nginx automatically distributes traffic to the new instance.
Round-robin (default, distributes in order) for most cases. least_conn for instances with different response times. ip_hash for WebSockets and sessions (same client always goes to same instance). weighted for instances with different capacities.
Add max_fails and fail_timeout to each server: server 127.0.0.1:3000 max_fails=3 fail_timeout=30s. Nginx removes the server after 3 failed attempts within 30 seconds and tries again after 30 seconds. No external health check endpoint needed.
Still have questions?
Browse all our FAQs or reach out to our support team
