0
0
NginxHow-ToBeginner · 3 min read

How to Stop Nginx: Simple Commands to Stop the Server

To stop nginx, use the command sudo systemctl stop nginx on systems with systemd. Alternatively, you can use sudo service nginx stop on older systems or sudo nginx -s stop to send a stop signal directly.
📐

Syntax

There are three common ways to stop the nginx server:

  • sudo systemctl stop nginx: Stops the nginx service using systemd, the modern service manager.
  • sudo service nginx stop: Stops nginx using the older service command.
  • sudo nginx -s stop: Sends a stop signal directly to the nginx process.

Use sudo to run commands with administrator rights.

bash
sudo systemctl stop nginx
sudo service nginx stop
sudo nginx -s stop
💻

Example

This example shows how to stop nginx using systemctl. It will stop the nginx service immediately.

bash
sudo systemctl stop nginx
sudo systemctl status nginx
Output
● nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: inactive (dead) since Fri 2024-06-07 10:00:00 UTC; 2s ago Process: 1234 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 1234 (code=exited, status=0/SUCCESS)
⚠️

Common Pitfalls

Common mistakes when stopping nginx include:

  • Running the stop command without sudo, causing permission denied errors.
  • Using nginx -s stop without specifying the correct user or permissions.
  • Confusing stop with reload, which only reloads configuration without stopping the server.

Always check the service status after stopping to confirm it stopped successfully.

bash
sudo nginx -s stop
sudo systemctl stop nginx
📊

Quick Reference

Use this quick reference to stop nginx safely:

CommandDescription
sudo systemctl stop nginxStop nginx using systemd (modern systems)
sudo service nginx stopStop nginx using service command (older systems)
sudo nginx -s stopSend stop signal directly to nginx process

Key Takeaways

Use sudo systemctl stop nginx to stop nginx on modern Linux systems.
Check nginx status after stopping to confirm it is inactive.
Avoid running stop commands without sudo to prevent permission errors.
Do not confuse stopping nginx with reloading its configuration.
Use nginx -s stop only if you need to send signals directly to the process.