How to Start, Stop, and Restart Nginx (systemctl & Nginx Commands)


Nginx is a powerful server application that routes network traffic. It is often used as a reverse proxy server, but can also be configured as a normal web server.

One of the most common operations you will encounter is to start, stop, and restart the Nginx web server.

In this tutorial, learn how to start, stop, and restart the Nginx service.


A system with Nginx

    installed and configured

  • Accessing a terminal or command line window
  • A user account with

  • sudo or root privileges An
  • existing SSH connection to a remote system (if you are working remotely)
  • Start, stop and restart Nginx with systemctl How to view the status of your server

Nginx Nginx runs as a service on your server. That means it should actively run in the background, even if you don’t see anything on the screen. You can display the

status of the Nginx service by entering the following command in a terminal window: sudo systemctl status nginx

The system will switch to a status mode, showing a lot of information about the Nginx service

. If the service is running (active), you will see

  • an active (running) green status on the third line
  • . If Nginx

  • is not running, it will be displayed as inactive in standard white
  • .

  • If something went wrong and Nginx failed to load, you will see a failed red status, with some information about the failure.

Press q to reactivate the bash indicator.

SystemD is the default service manager in modern versions of Linux distributions (Ubuntu 20.04/18.04/16.04, CentOS 7/7 and Debian 9/10). The SystemD administrator works through the systemctl command.

The systemctl command is a Linux base command. That means it can be used for any Linux service.

Stop and start Nginx systemctl can be used to start and stop the Nginx service. To stop Nginx, run the following command: sudo systemctl stop nginx To start Nginx, run the systemctl

command with the startup option: sudo systemctl

start nginx

How to restart


gracefully Restart


If you are updating Nginx after changing the settings, it is best to reload the service gracefully. That closes the old processes and restarts the new ones with the new settings.

Use the systemctl Linux command to reload the Nginx service. Run the following command:

sudo systemctl reload nginx


restart Nginx

For major configuration changes, you can force a full restart of Nginx. This forces all service and threads to shut down, and restarts the entire package.

Enter the following command:

sudo systemctl restart nginx

Restart vs Reload


The reload command keeps the Nginx server running while reloading the updated configuration files. If Nginx notices a syntax error in any of the configuration files, the reload is aborted and the server continues to run based on the old configuration files. Recharging is safer than restarting Nginx.

The restart command will shut down the server, including all related services, and turn it back on. Restart Nginx only when you make significant configuration updates, such as changing ports or interfaces. This command will force all worker processes to close.

Configure Nginx to start at boot Use the enable option with the systemctl command to enable Nginx: sudo systemctl enable nginx Use the disable option with the systemctl command to disable Nginx: sudo

systemctl disable


Start, stop, and reload

Nginx with the Nginx command Nginx

has a set of built-in tools for managing the service that can be accessed using the Nginx command.


Nginx To start

Nginx and related processes, enter

the following: sudo /etc/init.d/nginx start

If executed successfully, the terminal output will display the following:

Output [ ok ] Nginx startup (via systemctl): nginx.service. Restarting Nginx To force shut down and restart Nginx and related processes: sudo /etc/init.d/nginx restart Alternatively, use the command nginx -s: sudo nginx -s restart Nginx Stop To

disable or

stop the Nginx service, enter the following: sudo /etc/init.d/nginx stop

Alternatively, use:


nginx -s

stop Nginx Reload To stop and properly


Nginx and related

processes , Use the command

: sudo /etc/init.d/nginx reload Alternatively, you can use the nginx -s command to pass instructions directly to Nginx: sudo nginx -s reload Nginx Quit

Force Close the Nginx service using the quit statement with the nginx command -s: sudo nginx -s quit


This article has described several methods to start, stop, and restart Nginx on your server. Use these commands for the most common operations when administering an Nginx web server.