Install Nginx on Ubuntu 20.04 LTS Using Source Code - Step by step guide ?

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.

Here at LinuxAPT, we shall look into how to install Nginx on your Ubuntu Server 20.04 Linux system using Source Code.

To see how you can setup Nginx as reverse proxy on Ubuntu 20.04, visit: .

Steps to install Nginx on Ubuntu Server 20.04 LTS via Source Code

1. Perform System Update

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

2. Add latest Nginx PPA (Mainline)

Now, add latest Nginx PPA by running the command below:

$ sudo add-apt-repository ppa:ondrej/nginx-mainline -y && sudo apt update

3. Install Nginx

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.

4. Add Nginx source code to the repository

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.

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

5. Download Nginx source

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.

i. Create a directory

Make a directory like this:

$ sudo mkdir /usr/local/src/nginx && cd /usr/local/src/nginx

ii. Install dependencies and download the package

Now download the source package by running the command below:

$ sudo apt install dpkg-dev -y && sudo apt source nginx

6. Verify Nginx source version

Run the ls command to list down the directory's files:

$ ls

You will see the changes in the /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 will see that the source package and the Nginx Operating System should have the same version number. 

How to Uninstall Nginx from Ubuntu ?

1. Stop Nginx

To do that, first of all, stop Nginx as it will be running by using this command:

$ sudo systemctl stop nginx

2. Remove Nginx

Now delete Nginx installation by running the following command:

$ sudo apt-get purge nginx -y && sudo apt autoremove nginx -y

Now, Nginx will no longer be on your operating system.

[Need help in fixing Nginx configuration issues ? We can help you. ]

This article covers how you can easily install Nginx on your Ubuntu server. In fact, Nginx is used for security and load-balancing, but can also function independently as a web server. 

It was created on 4 October 2004 by Russian developer Igor Sysoev as he was frustrated with Apache web server and wanted to build a replacement capable of handling 10,000 concurrent connections with a focus on performance, high concurrency, and low memory usages.

How to Enable NGINX on Boot ?

So to enable start-up on boot, run this command:

$ systemctl enable nginx

So we get confirmation of a start-up, symlink being created for this service.

Related Posts