The objective of this article is to provide the user with an information how to restart NGINX on Ubuntu 20.04 Focal Fossa.
In this tutorial you will learn:
- How to gracefully reload NGINX on Ubuntu
- How to restart NGINX on Ubuntu
Software Requirements and Conventions Used
| Category | Requirements, Conventions or Software Version Used |
|---|---|
| System | Installed Ubuntu 20.04 or upgraded Ubuntu 20.04 Focal Fossa |
| Software | NGINX |
| Other | Privileged access to your Linux system as root or via the sudo command. |
| Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
How to restart NGINX on Ubuntu 20.04 step by step instructions
There are two main ways on how to restart the NGINX webserver on Ubuntu Linux:
- reload – reloads the configuration file and keeps any existing client connection intact
- restart – fully restarts the NGINX server and closes any existing client connections
Even though both above methods check the configuration during the restart/reload procedure it is always advisable to check the NGINX web-server configuration using the following command:
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Since the Ubuntu 20.04 Focal Fossa Server/Desktop is based on systemd the following two methods are recommended to restart the the NGINX web server.
You can check whether the NGINX web-server has been fully restarted by checking for
Main PID number using the sudo systemctl status NGINX command before and after the restart. - Using the
systemcltcommand gracefully reloads the NGINX webserver:$ sudo systemctl reload nginx
- This method fully restarts the NGINX web-server:
$ sudo systemctl restart nginx
