Sep 23, 2023 5 min read

Two Methods to Install NGINX on Debian 11

Two Methods to Install NGINX on Debian 11 with our step-by-step tutorial. NGINX is a versatile web server, load balancer and reverse proxy.

Two Methods to Install NGINX on Debian 11
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install NGINX on Debian 11, let's briefly understand – What is NGINX?

NGINX is a web server that may also be used as a load balancer, HTTP cache, mail proxy, and reverse proxy. A mechanism used to optimize the World Wide Web (WWW) is referred to as HTTP cache (also known as Web cache). As implied by the name, load balancing is a method of assigning various jobs to various computing devices. While a reverse proxy receives information from many sources and sends it back to the client, a proxy server mostly manages load.

A Russian engineer began working on NGINX in 2002, and it was made available to the general public in 2004. NGINX became the greatest tool for caching, web serving, and reverse proxies after that public release. Millions of websites began using NGINX over time in order to improve performance and scalability. NGINX is used by organizations including Facebook, Microsoft, IBM, Google, Adobe, and LinkedIn.

In this tutorial, you will install NGINX on Debian 11. We will also address a few FAQs on how to install NGINX on Debian 11.

Advantages of NGINX

  1. High performance: NGINX’s event-driven architecture and efficient handling of concurrent connections allow for excellent performance under heavy loads.
  2. Scalability: NGINX can handle thousands of concurrent connections, making it a great choice for high-traffic websites.
  3. Load balancing: NGINX’s built-in load balancing capabilities distribute traffic evenly across multiple servers, improving reliability and performance.
  4. Reverse proxying: NGINX acts as a reverse proxy, providing an extra layer of security and enabling easy management of backend servers.
  5. High availability: NGINX supports active-passive and active-active cluster configurations, ensuring high availability and fault tolerance for critical applications.

How NGINX works

The foundation of NGINX concentrates on delivering a high concurrent output while utilizing less memory and employs the master and slave/worker phenomena: For instance, the Master process reads the configuration settings, binds them to ports, and then launches a number of worker/slave processes. All operations are now managed by workers as a result of the creation of worker processes. There are two more processes called the cache loader and cache manager in between the worker and master processes. The cache loader only functions to load cache (disk-based) into memory, and since it ends after doing so, it consumes fewer resources. Cache manager, however, maintains the entries of the disk cache in a configured and organized manner.

How to Install NGINX on Debian 11 Bullseye

Following are the instructions for installing NGINX on a Debian 11 system: You can do this by using any of the suggested techniques:

  • Using Debian 11 repository
  • Using NGINX official repository

The following sections provide examples of the procedures used in both methods:

Installing NGINX on Debian 11 using default repository

You can follow this technique to install NGINX from the Debian 11 repository:

Step 1: Update the packages on Debian 11 Bullseye

The first, and most advised, step is to update your Debian 11's package list:

 sudo apt update

Step 2: Install NGINX

You can use the command shown below to install NGINX after the packages list has been updated:

sudo apt install nginx

Step 3: Verify the installation

Use the following command to determine the NGINX version that is currently installed:

sudo nginx -v

Additionally, you can verify that the NGINX server is operational by using the command listed below:

curl -I 127.0.0.1

Installing NGINX on Debian 11 from official NGINX repository

The procedures that must be taken to install the most recent version of NGINX using this approach are as follows:

Step 1: Add NGINX signing key

Utilize the following command to download the key for signing NGINX:

sudo wget https://nginx.org/keys/nginx_signing.key 

And using the command listed below, you may add the downloaded key to apt's program key ring:

sudo apt-key add nginx_signing.key

Step 2: Edit the sources.list file

First, open the sources.list file in any editor of your choice. The command shown below will open the file in the nano editor:

sudo nano /etc/apt/sources.list

To install NGINX on Debian 11 (Bullseye), add the following lines to the source.list file:

Note: If you wish NGINX for other Debian releases, simply substitute "bullseye" for the code name of that release in the lines below:

deb https://nginx.org/packages/mainline/debian/ bullseye nginx
deb-src https://nginx.org/packages/mainline/debian bullseye nginx

Save using "Ctrl+S" and exist the editor by entering "Ctrl+X".

Step 3: Install NGINX

Use the command listed below to update the packages list:

sudo apt update

And then run the following command to install NGINX:

sudo apt install nginx
💡
If faced some issues with dependencies then fix by using command sudo apt --fix-missing install

How to Uninstall NGINX from Debian 11

You must make sure to empty the "/var/www/html" directory before running the remove command by running the following command:

sudo rm -rf /var/www/html

NGINX and all of its dependencies can now be deleted using the command listed below:

sudo apt purge nginx nginx-common

FAQs to Install NGINX on Debian 11

Where can I find the NGINX configuration file on Debian 11? 

The main NGINX configuration file can be found at /etc/nginx/nginx.conf on Debian 11.

How can I start NGINX service on Debian 11? 

To start the NGINX service on Debian 11, use the command sudo systemctl start nginx.

How can I enable NGINX to start automatically on boot in Debian 11? 

You can enable NGINX to start automatically on boot by running sudo systemctl enable nginx.

What is the default web root directory for NGINX on Debian 11? 

The default web root directory in Debian 11 is /var/www/html/.

How can I check the status of NGINX service in Debian 11? 

To check the status of NGINX service, use the command sudo systemctl status nginx.

How do I restart NGINX service on Debian 11? 

To restart NGINX service on Debian 11, run sudo systemctl restart nginx.

Can I use NGINX as a reverse proxy on Debian 11? 

Yes, NGINX can be used as a reverse proxy on Debian 11. Configure the appropriate settings in the NGINX configuration file.

Are there any additional steps required for HTTPS setup with NGINX on Debian 11?

Yes, additional steps like obtaining and installing SSL certificates are needed for HTTPS setup. NGINX can be configured accordingly.

Conclusion

NGINX is a well-known web server with open-source access that is employed by top-tier enterprises due to its broad support for HTTP cache, reverse proxying, load balancers, and other features. To install NGINX on Debian 11, we've given a tutorial that details two methods: When using Method 1, you can run into outdated packages because NGINX is installed using Debian 11's default repository. In this case, the second method can be used to get the most recent NGINX version from the NGINX official source.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.