How To Start, Stop, Or Restart Nginx
This guide explains how to start, stop, and restart Nginx on Linux servers.
Nginx pronounced “engine x” is a free, open-source, high-performance HTTP and reverse proxy server responsible for handling the load of some of the largest sites on the Internet. It can be used as a standalone web server or as a reverse proxy for Apache and other web servers.
The instructions assume that you are logged in as root or user with sudo privileges.
Most of the current Linux distributions are using SystemD as the default init system and service manager. Older distributions are based on SysVinit and using init scripts to manage services.
Both SystemD service units and SysVinit script takes the following arguments to manage the Nginx service:
start: Starts the Nginx service.
stop: Terminates the Nginx service.
restart: Stops and then starts the Nginx service.
reload: Gracefully restarts the Nginx service. On reload, the main Nginx process shuts down the child processes, loads the new configuration, and starts new child processes.
status: Shows the service status.
The commands for managing the Nginx service are the same on all Linux distributions.
Start, Stop and Restart Nginx using systemctl
SystemD is a system and service manager for the latest Ubuntu 18.04 /16.04 , CentOS 7 /8 , and Debian 10 /9 releases.
Whenever you make changes to the Nginx configuration, you need to restart or reload the webserver processes. Execute the following command to restart the Nginx service:
When adding or editing server blocks, prefer reloading over restarting. Restart the service only when making significant modifications like changing ports or interfaces. On reload, Nginx loads the new configuration, starts new worker processes with the new configuration, and gracefully shuts down old worker processes.
Run the command below to reload the Nginx service:
Nginx can also be directly controlled with signals . For example, to reload the service, you can use the following command:
To start the Nginx service, execute:
Execute the following command to stop the Nginx service:
Start, Stop and Restart Nginx using SysVinit
Older (EOLed) versions of Ubuntu, CentOS, and Debian are using init.d scripts to start, stop and restart the Nginx daemon.
Restart the Nginx service:
Start the Nginx service:
Stop the Nginx service:
We have shown you how to start, stop, and restart the Nginx web server on Linux systems.