How to Start, Stop and Restart NGINX on Ubuntu 22.04?


Nginx is a widely used web server used to serve web applications. It also serves as a load balancer and HTTP proxy.

Today, we will explore different commands using which we can start, stop, and restart the Nginx web server on Ubuntu 22.04. The commands are very much similar to each other and easy to follow. Before jumping to the guide, make sure Nginx is installed and configured on your Ubuntu system.

Without any further ado, let’s get started!

Prerequisites

Starting, Stopping, and Restarting Nginx on Ubuntu 22.04

Following are some of the ways we can change the status of Nginx:

Method 1: systemctl command

The first method involves the use of systemctl command to change the status of Nginx like this:

sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx

Start-Stop-Restart-Nginx

Method 2: service command

In the second method, we make use of another command ‘service’ to start, stop and restart Nginx. The command is pretty much similar to systemctl, only that we replace systemctl with a service like this:

sudo service nginx start
sudo service nginx stop
sudo service nginx restart

Start-Stop-Restart-Nginx

Method 3: via init.d directory

The third method involves running or stopping the Nginx service directly from its location. This can be achieved using the commands like this:

sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx restart

Star-Stop-Restart-Nginx

Verify Nginx Status

Once you have stopped or started the Nginx service, you can verify the status with any of the following commands:

sudo systemctl status nginx

OR

sudo service nginx status

If Nginx is running fine, you will see the following output on Linux Terminal:

start-stop-restart-Nginx

If the service is stopped, you will see inactive in the status output.

start-stop-restart-Nginx

Conclusion

In today’s guide, we saw in detail three ways through which we can start, stop, and restart Nginx on a Linux machine. We first explored systemctl and service commands. Then, we saw how to start, restart, and stop Nginx by running the commands directly through init.d directory.

We hope you liked the tutorial.

Print Friendly, PDF & Email
Categories