How to Start, Stop or Restart NGINX on Ubuntu

This quick guide will show you how to start, stop or restart the NGINX web server on your Ubuntu device.

Ubuntu start, stop, or restart NGINX

If you have the performance-friendly NGINX web server installed on Ubuntu, you will likely want to know how to control it.

You might want to restart NGINX on your system for various reasons, such as a core configuration change.

Systemd is the system and service manager Ubuntu has used since 14.04. While older versions of Ubuntu relied on different methods, we will focus purely on using systemctl within this guide.

Over the following sections, we will show you how to start, stop, restart, or reload the NGINX process on Ubuntu.

How to Restart NGINX On Ubuntu

If you need to restart the NGINX web server on Ubuntu, you can use the simple command below.

There are various reasons why you might want to restart NGINX on your system, such as a core configuration change.

What this command does is send a restart request to the service manager. This service manager then restarts the service with the name “nginx“.

sudo systemctl restart nginx

You will want to utilize the command below to check whether you successfully restarted NGINX on Ubuntu. This command retrieves the status of the NGINX service.

sudo systemctl status nginx

You can check when NGINX was last restarted/started on Ubuntu by looking at the “Active:” line. At the end of the line, you will see how long the service has been running.

For example, NGINX has been running for 1 second on our system.

Active: active (running) since Sun 2023-04-23 06:45:47 BST; 1s ago

How to Start NGINX on Ubuntu

If, for some reason, the NGINX web server has been stopped on Ubuntu, it is relatively easy to get it up and running again.

To start NGINX on Ubuntu, you will want to use the following command. Make sure you write “systemctl” followed by “start” and then finally “nginx“.

sudo systemctl start nginx

One of the most obvious ways to check whether you have started NGINX is to try connecting to the web server. However, it is also possible to check this from within the terminal by retrieving the service’s status.

Using the command below, you will get the status of the NGINX service.

sudo systemctl status nginx

To verify your service is working, you will want to look at the “Active:” line and look for the text saying “active (running)“.

Active: active (running) since Sun 2023-04-23 11:31:24 BST; 1s ago

How to Stop NGINX on Ubuntu

If you want to stop the NGINX web server on Ubuntu, you only need to use the following command within the terminal.

This command will send a stop signal to the NGINX process allowing it to shut down gracefully.

sudo systemctl stop nginx

By checking the service status with the following command, you can verify that you have stopped NGINX on your Ubuntu device.

sudo systemctl status nginx

If you have successfully stopped the NGINX server, you will see that the “Active:” line shows that status as “inactive (dead)“.

Active: inactive (dead) since Sun 2023-04-23 11:31:42 BST; 1s ago

How to Reload NGINX on Ubuntu

You don’t have to stop or restart the NGINX web server on Ubuntu for configuration changes to take effect.

Instead, you can use the reload command to tell NGINX to reload all its configuration files without restarting the web server.

sudo systemctl reload nginx

You will now want to check whether NGINX has reloaded by grabbing the service status on Ubuntu.

sudo systemctl status nginx

Now you will want to look at the log messages output by the NGINX service. Primarily you will want to see the following messages indicating you reloaded the web server.

Apr 23 11:32:01 pimyubu systemd[1]: Reloading A high performance web server and a reverse proxy serv>
Apr 23 11:32:01 pimyubu systemd[1]: Reloaded A high performance web server and a reverse proxy serve>

Conclusion

Hopefully, by now, you will understand how to start, stop, restart or reload the NGINX web server on Ubuntu.

Controlling the NGINX service is made effortless thanks to systemd. This tool allows us to control the status of the service easily.

Please comment below if you have encountered any issues with starting, stopping or restarting NGINX.

If you found this guide helpful, be sure to check out our many other Ubuntu tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *