Besides Apache, Nginx is the most popular open source web server in use today. NginX is also known as powerful load balancing and reverse proxy. It was initially designed to solve scaling and concurrency problems with existing web servers. Currently, the NginX is responsible for hosting some of the largest and highest-traffic sites on the internet. At this article we will discuss how to install Nginx on Ubuntu 18.04.
At this article, installing Nginx will be divided up to several section.
- Installing NGINX
- Verify NGINX Services
- Adjusting the Firewall
- Checking NGINX Application
For detail steps, it will be described briefly at the next section below.
The Nginx is available as default repositories on Ubuntu Linux, it is possible to install it from these repositories using the
apt packaging system. Before we begin the installation process, we should have a regular, non-root user with sudo privileges configured on our server. And also our system has sufficient disk size and internet connection, if the installation need the newer update.
Nginx has been available as Ubuntu’s default repositories, so we use this repositories for installing Nginx by using the
apt packaging system. As always we do any installations on our system we will update our local package index so that we have access to the most recent package listings. Afterwards, we can install
ramans@ubuntu:~$ sudo apt update
The next step is just installing the nginx software from an existing updated Ubuntu repositories.
ramans@ubuntu:~$ sudo apt install nginx
Until now, the Nginx installation was completed done, where the Nginx package has been unpacked and copied to the system.
After installation, the next step is to verify if the web server has been already be up and running. We can check with the
systemd init system to make sure the service is running by typing:
ramans@ubuntu:~$ systemctl status nginx
Nginx registers itself as a service with ufw upon installation. Before testing Nginx, the firewall software needs to be adjusted to allow access to the Nginx services. Making it straightforward to allow Nginx access. To verify the firewall, it can be execute the command below :
ramans@ubuntu:~$ sudo ufw app list
The output could be :
Available applications: CUPS Nginx Full Nginx HTTP Nginx HTTPS
There are three profiles available for Nginx :
Nginx Full: open both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
Nginx HTTP: open only port 80 (normal, unencrypted web traffic)
Nginx HTTPS: open only port 443 (TLS/SSL encrypted traffic)
We can enable one of three or all profiles, with the command:
ramans@ubuntu sudo ufw allow 'Nginx HTTP'
The next step is to verfify the firewall status by submiting command :
sudo ufw status
After verifiying Nginx services and allowing the port on firewall adjustment steps, the last step is to check the Nginx applications. It should be running and binding on http service. The test is just a small task by using browser we just hit the url as
Note : to know the ip address in our system, we can check by submiting the command
ifconfig -a, as shown below.
ramans@ubuntu:~$ ifconfig -a ens33: flags=4163 mtu 1500 inet 192.168.59.148 netmask 255.255.255.0 broadcast 192.168.59.255 inet6 fe80::9567:7aa6:9181:90e9 prefixlen 64 scopeid 0x20 ether 00:0c:29:7c:03:98 txqueuelen 1000 (Ethernet) RX packets 23547 bytes 30721219 (30.7 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 12589 bytes 1006618 (1.0 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 1000 (Local Loopback) RX packets 709 bytes 70527 (70.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 709 bytes 70527 (70.5 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0