This article covers how to install Nginx on the Ubuntu system. Also, you will learn how to configure the firewall and manage Nginx services.
Finally, you will see how to uninstall Nginx in case you no longer need it in your system.
Nginx is a free, open-source Linux application for web servers. It works as a reverse proxy server by directing web traffic to specific servers.
Also, Nginx is used for security and load-balancing, but can also function independently as a web server.
To Install Nginx From Ubuntu Repositories:
1. Update Software Repositories
It is important to refresh the repository lists before installing new software. This helps make sure that the latest updates and patches are installed.
Open a terminal window and enter the following:
$ sudo apt-get update
2. Nginx is included in the Ubuntu 20.04 default repositories. Install it by entering the following command:
$ sudo apt-get install nginx
How to manage Nginx on Ubuntu ?
The behavior of Nginx can be adjusted. Use this to start or stop Nginx, or to enable or disable Nginx at boot.
Start by checking the status of the Nginx service:
$ sudo systemctl status nginx
If the status displays active (running), Nginx has already been started.
Press CTRL+z to exit the status display.
If Nginx is not running, use the following command to launch the Nginx service:
$ sudo systemctl start nginx
To set Nginx to load when the system starts, enter the following:
$ sudo systemctl enable nginx
To stop the Nginx service, enter the following:
$ sudo systemctl stop nginx
To prevent Nginx from loading when the system boots:
$ sudo systemctl disable nginx
To reload the Nginx service (used to apply configuration changes):
$ sudo systemctl reload nginx
For a hard restart of Nginx:
$ sudo systemctl restart nginx
To Test the Configuration
$ sudo nginx –t
The system should report that the configuration file syntax is OK, and that the configuration file test is successful.