Adding NGINX as a system service
In this section, we will create a script that will transform the NGINX daemon into an actual system service. This will result in mainly two outcomes—the daemon will be controllable using standard commands and, more importantly, it will automatically be launched on system startup and stopped on system shutdown.
systemd unit file
Most Linux-based operating systems to date use a systemd-style service file. Debian, Ubuntu, RHEL, and centOS all use systemd nowadays; therefore, this service file should work on any popular linux distribution. There is other init software, such as System V and OpenRC; however, we will stick with the more popular and most supported init.
In this example, we will be using the NGINX service file provided by the official NGINX website:
- Create a file by using the following command:
nano /etc/systemd/system/nginx.service
Figure 1.3: Default systemd service file for Nginx
Note...