Nginx is open-source software that works as a web server, reverse proxy, load balancer and so much more. It was specially designed to render maximum performance and high stability.
The software follows a master-slave architecture, with one master process maintaining multiple slave processes. Nginx was developed by a Russian developer Igor Sysoev as he was frustrated with the Apache web server and wanted a better replacement that could handle 10,000 concurrent connections with low memory usage. Thanks to him, the Nginx web server came into being. Today, Nginx serves some of the world’s top websites and its growth seems to be only going up.
Now let’s see how can we get Nginx on our system with a few easy steps.
To install Nginx on Ubuntu server, we have two methods:
For this tutorial, we have followed the second method. I will show you how you can install Nginx on your Ubuntu server with the help of its source code. Let’s begin!
Before beginning the installation, update and upgrade your operating system with the help of the command below so that you only have updated packages on your server.
sudo apt update && sudo apt upgrade -y
This step will commence the installation process. To begin, add latest Nginx PPA by running the command below. In this tutorial, we are installing the mainline PPA.
sudo add-apt-repository ppa:ondrej/nginx-mainline -y && sudo apt update
After installing the PPA and updating the repository list, you will install Nginx with this command:
sudo apt install nginx-core nginx-common nginx nginx-full
After running this command, you may be asked if you want to keep or replace your existing /etc/nginx/nginx.conf configuration file during installation. We recommend that you keep this existing config file by pressing n. This will allow a copy of the file to be made that you can use in the future if needed.
When installing PPA, by default the source code will not be installed. First, you will have to manually enable it. To do that, open the configuration file in /etc/apt/sources.list.d with an editor as shown below:
sudo nano /etc/apt/sources.list.d/ondrej-ubuntu-nginx-mainline-*.list
Now locate this line and uncomment it by removing the hash symbol.
This is how it should look like:
Now save the file by pressing control + X, then Y and hit enter. The changes will be saved.
Now update the repository list like this:
sudo apt update
Next, we will download Nginx source code in case you need to compile a dynamic module later. To do that, you need to download and add the source package in the location /etc/local/src/nginx.
Make a directory like this:
sudo mkdir /usr/local/src/nginx && cd /usr/local/src/nginx
Now download the source package by running the command below:
sudo apt install dpkg-dev -y && sudo apt source nginx
After running the command, you may come across an error as shown below. It is safe to ignore it.
Run the ls command to list down the directory’s files:
ls
This is how the list will appear in your /usr/src/local/nginx directory:
Now run the command below to make sure the source package version is the same as the Nginx version you just installed on your Operating System.
nginx -v
You should get a similar output as shown below. This means the source package and the Nginx Operating System should have the same version number. In our case, it is 1.21.1.
If you have made it this far, congratulations, you have successfully installed Nginx.
Now that we have seen how to install Nginx, let’s also have a look at how to uninstall it.
To do that, first of all, stop Nginx as it will be running by using this command:
sudo systemctl stop nginx
Now delete Nginx installation by running the following command:
sudo apt-get purge nginx -y && sudo apt autoremove nginx -y
After this, Nginx will no longer be on your operating system.
In this tutorial, you saw how you can easily install Nginx on your Ubuntu server with the help of a few easy-to-follow commands. You also saw how you can remove Nginx from your system with the help of two simple commands.
To see how you can setup Nginx as reverse proxy on Ubuntu 20.04, visit:
https://linuxways.net/ubuntu/how-to-set-up-nginx-as-reverse-proxy-on-ubuntu-20-04/
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.
One of the most critical gaps in traditional Large Language Models (LLMs) is that they…
Canonical is continuously hiring new talent. Being a remote- first company, Canonical’s new joiners receive…
What is patching automation? With increasing numbers of vulnerabilities, there is a growing risk of…
Wouldn’t it be wonderful to wake up one day with a desire to explore AI…
Ubuntu and Ubuntu Pro supports Microsoft’s Azure Cobalt 100 Virtual Machines (VMs), powered by their…
Welcome to the Ubuntu Weekly Newsletter, Issue 870 for the week of December 8 –…