Although Nginx is very stable and easily manageable, as a system administrator, you will encounter instances where you need to start, stop, or restart Nginx; for example, you may want to apply configuration changes or troubleshoot errors on the server.
This tutorial will discuss how to start, stop and restart the Nginx server on Linux systems using Systemd.
Pre-requisites
Before we proceed with the tutorial, it is good to ensure you have the following:
- Ensure you have Nginx installed and configured properly
- Have access to the root user or a sudo account.
With the above requirements met, we can begin:
What is Systemd?
Systemd is an init and service manager for Linux systems. Major Linux distributions, including Debian, Arch, REHL, and Fedora, have adopted Systemd. Systemd allows system administrators to start, stop, reload and restart services in the system. It also provides features such as logging, which is very useful in troubleshooting measures.
If you want to learn more about systemd, please consider the official documentation: https://systemd.io/
How to Manage The Nginx Service
Managing the Nginx service is quite simple, mainly because of the ease of use that Systemd gives us.
How to Start Nginx
To start the Nginx service on a Linux machine, use the command:
Assuming no encountered errors, you should see no output, and Nginx should be up and running.
Suppose you are not a system that uses init.d instead of the system; in that case, to start Nginx, use the command:
How to Stop Nginx service
In this case, the reverse is true. To stop Nginx service with systemd, the command is as:
Using init.d? use the command:
Reloading Nginx service
Nginx service also supports the reload function. This loads new configurations and restarts the worker processes using the loaded configuration. Reload feature is useful if you do not want to perform a complete reboot of the service.
To reload Nginx with systemd, use the command:
Use the command below for init.d systems.
Restarting Nginx service
Unlike reload, restarting the Nginx service will fully stop and start the server. To restart Nginx, use the command:
The command for SysVinit is:
Conclusion
This tutorial showed you how to manage the Nginx service on Linux systems, including those using Systemd and Init.d.