Nginx is one of the most famous & widely used web servers. Nginx not only acts as a web server but can also work as a mail proxy server, reverse proxy, cache server as well as a load balancer.
In this tutorial, we will learn how to install NGINX on Ubuntu using the Ubuntu system repositories & also with using Nginx repositories.
Recommended Read: How to install Nginx on CentOS/RHEL
So let’s get start.
Install Nginx on Ubuntu using the Ubuntu repositories
nginx is maintained on the default Ubuntu repositories & can be installed with the default package manager i.e. apt. To install Nginx on Ubuntu, run the following command,
$ sudo apt update && sudo apt upgrade -y
$ sudo apt install nginx
Once the nginx is installed, the nginx service will install by default. We can check it by running the following command,
$ systemctl status nginx
$ ps -ef | grep nginx
If it’s not running, we can start the server by the following command,
$ systemctl start nginx
To enable the nginx service at the boot time, execute the following command,
$ systemctl enable nginx
Once the webserver is up and running, we can also access the default webpage for Nginx. All we need is the system IP address or if you are trying to access the webpage on the localhost, then we can also access the webpage with either ‘localhost’ or ‘127.0.0.1’ as the URL.
Install Nginx using the Official Nginx Repositories
To install the official nginx repositories, we need to first install the keys that are used to sign the NGINX packages,
$ sudo wget https://nginx.org/keys/nginx_signing.key
$ sudo apt-key add nginx_signing.key
Next, we will add the repositories in the file ‘/etc/sources.list’,
$ vim /etc/sources/list
deb https://nginx.org/packages/mainline/ubuntu/ <CODENAME> nginx
deb-src https://nginx.org/packages/mainline/ubuntu/ <CODENAME> nginx
Here, <CODENAME> refers to the code the Ubuntu version being used, list is mentioned below,
So for Ubuntu 20.04, we need to add the following entries to ‘/etc/sources.list’,
deb https://nginx.org/packages/mainline/ubuntu/ groovy nginx
deb-src https://nginx.org/packages/mainline/ubuntu/ groovy nginx
Once done, save the file & exit & run the following command to install nginx on Ubuntu,
$ sudo apt update && sudo apt upgrade
$ sudo apt install nginx
Check the Nginx service & access the webserver to access the default webpage. So this completes our tutorial on how to install Nginx on Ubuntu. In our next tutorial, we will discuss how we can create the webserver blocks to host multiple websites on a single Nginx webserver.