Are you looking to restart the Nginx webserver using command line options? If you are using a Linux or Unix-like system, then Nginx is a good option for a web server. It is free and open-source. Now let us see how to restart Nginx using the command line interface (CLI).
To restart the nginx web server, run the following commands as root user, depending on your Linux OS version.
First, determine your Linux distribution: cat /etc/os-release
- Open a terminal and run the ssh command to connect to the remote server.
ssh example@server1.cyberciti.biz
- Restart Nginx using systemd init on Linux.
sudo systemctl restart nginx.service
- Type the older versions of Linux using sysv init:
sudo service nginx restart
Below is the command to restart the Nginx server based on your Linux init type, which may be systemd, sysvithe nit, OpenRC, or others. The relevant command to restart the Nginx server will be available depending on your init type and Linux distribution version.
To restart the Nginx web server on Debian or Ubuntu Linux, run the following command:
# /etc/init.d/nginx restart
Or # /etc/init.d/nginx reload
For sysv init-based systems, you can use the service command:
# service nginx restart or
# service nginx reload
If you are running a systemd-based Linux distribution:
sudo systemctl restart nginx or
sudo systemctl reload nginx
To check the status:
# service nginx status or
sudo systemctl status nginx
Restart the Nginx on Alpine Linux
Run the following command on Alpine Linux:
/etc/init.d/nginx restart
Find the Binary Path to restart or reload the server
Nginx includes delivering signals to a master (main) process. This will work on any Linux distribution or Unix-like operating system.
# nginx - s signal
To find the path of the Ngnix binary, use the following command:
# type nginx
The entire path of the nginx binary
/usr/sbin/nginx
Managing the Ngnix Webserver
To Reload the Nginx webserver
# nginx -s reload or # /usr/sbin/nginx -s reload
To stop the Nginx webserver
# nginx -s stop
or
# /usr/sbin/nginx -s stop
To quit or exit the Ngnix web server: Send SIGQUIT to the main process, then quit.
# nginx -s quit
or
# /usr/sbin/nginx -s quit
If the nginx binary is installed under /usr/local/nginx/sbin/nginx:
# /usr/local/nginx/sbin/nginx -s reload
Check the nginx server config errors
To check the setup, run the Nginx command using the -t option and exit
# nginx -t
Enter -T to test configuration
# nginx -T
Send signal to Nginx
Linux and Unix users use the following command:
# nginx -s signal
The signal can be stopped, quit, reopened, or reloaded. For example, as a root user, you can send the reload signal as follows:
# nginx -t # nginx -s reload
Check the Nginx version by using the -v or -V:
# nginx -v
Outputs: nginx version: nginx/1.21.5 # nginx -V
You can effectively manage and restart the NGINX web server based on your Linux distribution. Use sudo systemctl restart nginx for systemd systems and sudo service nginx restart for sysv init. You can also reload configurations and test for errors with nginx -s reload and nginx -t. These commands help ensure the smooth operation of your Nginx server across different Linux distributions. If you need any technical assistance, feel free to contact us for support!
To get more updates you can follow us on Facebook, Twitter, LinkedIn