nginx -s stop vs quit: Key Differences in Graceful vs Immediate Server Termination


1 views

When managing an Nginx server, both nginx -s stop and nginx -s quit commands are used for shutting down the server, but with fundamentally different behaviors:

# Immediate termination (stop)
nginx -s stop

# Graceful shutdown (quit)
nginx -s quit

nginx -s stop (TERM signal):

  • Sends SIGTERM signal to master process
  • Immediately terminates all worker processes
  • Active connections are dropped abruptly
  • No new connections are accepted after command execution

nginx -s quit (QUIT signal):

  • Sends SIGQUIT signal to master process
  • Gracefully shuts down worker processes
  • Workers finish serving current requests before exiting
  • New connections are immediately refused

When to use -s stop:

# Emergency situations needing immediate shutdown
sudo nginx -s stop

When to use -s quit:

# Normal maintenance with zero-downtime requirements
sudo nginx -s quit

Here's how the processes behave differently:

# Check process status after quit command
ps aux | grep nginx
# Master process remains until workers finish

# Versus stop command behavior
ps aux | grep nginx
# All processes terminate immediately

Both commands differ from reload operation:

# For comparison:
nginx -s reload  # Keeps server running while applying new config

Understanding these differences is crucial for proper server maintenance and avoiding service interruptions during deployments.


When managing Nginx servers, two commonly used commands are:

nginx -s stop
nginx -s quit

While both commands shut down the server, their underlying mechanisms differ significantly in how they handle existing connections.

Using -s stop sends a TERM signal to the Nginx master process, which immediately terminates all worker processes:

# This performs an immediate shutdown
sudo nginx -s stop

Key characteristics:

  • Abrupt termination of all worker processes
  • Active connections are dropped immediately
  • No waiting for requests to complete
  • Equivalent to sending SIGTERM directly

Using -s quit sends a QUIT signal, initiating a graceful shutdown:

# This performs a graceful shutdown
sudo nginx -s quit

Key characteristics:

  • Worker processes continue serving existing connections
  • No new connections are accepted
  • Workers exit after completing current requests
  • Clean shutdown maintains service integrity

For production environments, -s quit is generally preferred as it:

# Recommended for production servers
nginx -s quit

# Only use stop for emergency situations
nginx -s stop

Example where graceful shutdown matters:

  • E-commerce sites processing payments
  • APIs handling critical transactions
  • Applications with long-running requests

You can check active connections during shutdown:

# Monitor active connections
watch "netstat -an | grep :80 | grep ESTABLISHED"

This helps visualize how each command affects existing connections differently.

For more control, you can send signals directly to the master process:

# Get master process ID
cat /run/nginx.pid

# Send QUIT signal directly
kill -QUIT $(cat /run/nginx.pid)

# Send TERM signal directly
kill -TERM $(cat /run/nginx.pid)