Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  How to install Nginx on Ubuntu 16.04?
Top Scroll

How to install Nginx on Ubuntu 16.04?

 3 min

Nginx is a Linux web server that can be used as a reverse proxy, load balancer, mail proxy, and HTTP cache. It accelerates the content by utilizing very low resources and thus is known as a competitor to Apache. To install Nginx on Ubuntu 16.04 follow the steps mentioned in the tutorial.

Prerequisite :

To explain this tutorial we are working on Ubuntu 16.04 LTS server and also logged in as root.

#Steps to install Nginx

1) Update Apt-Get

First, we will update and upgrade our packet manager using the following command.

apt-get update && apt-get upgrade

2) Install Nginx

Below command will install Nginx

apt-get -y install nginx

3) Verify the installation of Nginx

If the Nginx is installed correctly, then an Nginx’s default file will get appear in /var/www/html as index.nginx-debian.html . In case you see the Apache default page then rename it as index.html file. Just like Apache, the port for Nginx is also port 80, which indicates that if you already have set your record A for your server’s hostname, then you can visit the IP and verify if the installation of Nginx is completed. By the following command if you can get the IP of your server, in case if you don’t have :

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Now, use this IP command and visit via HTTP (http://xxx.xxx.xxx.xxx).

Now you can see a similar screen as below, to verify the installation of Nginx.

Nginx welcome

How to change ports for Apache?

In case if you already have Apache established to port 80, then you may find the Apache default page when you visit your host IP. So, you can change this port, in order to make a place for Nginx to take over port 80. To change the Apache port, you will have to visit the Apache port configuration file :

vim /etc/apache2/ports.conf

Here, change “Listen 80” to any other port number, for example, we can use port 8080 :

Listen 8080

Now, to notice the changes, restart Apache,

service apache2 restart

All the things that Apache has can now be seen using your IP by replacing the x’s.

For example http://xxx.xxx.xxx.xxx:8080.

Also Read :

1) How to Block IPs with Nginx?

2) Steps to Redirect URLs Using Nginx

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.