How to start, stop and restart Nginx on Linux?

Nginx, which is pronounced as ‘engine x’ is a free, open-source, and high-performance HTTP server. It is among the most popular web servers that host some largest and most trafficked websites on the internet. As we already discussed how to set up Nginx server in Linux.

In this article, we will discuss how to start, stop and restart Nginx on a Linux system which is a common task for web application developers and system admins.

Start, stop and restart the Nginx using systemctl

Most of the modern Linux distributions today uses systemd as init system. On these systems, we can use the systemctl command to manage services.

Use the following command to start the Nginx service on your system –

sudo systemctl start nginx

To check the status, if the server is running or not use –

sudo systemctl status nginx

If the server is running correctly then it will display –

Generally, you need to restart your server after making changes in the configuration file. You can use the following command to restart the Nginx server on your system –

sudo systemctl restart nginx

If you want to stop Nginx on a system then use –

sudo systemctl stop nginx

Start, stop and restart the Nginx using the service command

Sysvinit is a traditional init system for Unix/Linux whose primary purpose is initializing, managing, and tracking system services and daemons. The older version of many Linux distributions uses sysvinit. We can use the service command to manage services on these systems.

To start Nginx server use –

sudo service nginx start

To check the status of the Nginx server that if it is running properly or not, use –

sudo service nginx status

If you want to restart the Nginx server on your system then use –

sudo service nginx restart

To stop the Nginx server use –

sudo service nginx stop

Conclusion

There are multiple ways in which you can start, stop or restart the Nginx service on a Linux system. Now if you have a query on this then write us in the comments below.

Leave a Comment