How To Install Nginx on Debian 12

Nginx is a high-performance scalable and efficient open-source web server responsible for serving website content on the user’s request. The applications for Niginx include reverse proxy, mail proxy, and HTTP cache and load balancer. Debian being one of the Linux stable distributions provides a solid foundation for Ngnix along with long-term support releases. So if you are looking to install Nginx on Debian then read this guide.

2-Ways To Install Ngnix on Debian 12

There are primarily two ways to install Nginx on Debian 12 which include using its default app installer which is apt and the other is by using Nginx’s official repository. Further to make Nginx work there are some configuration steps as well which this blog post will explain in detail.

1: Through Debian Default App Installer

The first method of installing Nginx on Debian 12 is using an apt app installer. This method is relatively easier than the other one but the version of Nginx here is a little bit older. To install Nginx on Debian using apt execute the below command:

sudo apt install nginx -y

Installing Nginx on Debian using apt package manager

After completion of Nginx installation check its version just for confirmation by executing the following command:

sudo nginx -v

Checking the version of Nginx on Debian 12 installed through apt package manager

2: Through Nginx Offical Repository

The second and last method to install Nginx on Debian is by using its official repository. This method is quite long but it gives two version options one is the mainline and the other is the stable version. The mainline version will be the latest one but might have bugs. However, the stable version will be a little older but there will be minimal bugs and errors. To install Nginx on Debian first you need to install some utilities in case you have freshly installed it:

sudo apt install curl gnupg2 ca-certificates lsb-release debian-archive-keyring

Installing some necessary utilities on Debian to install Nginx using its official repository.

Next, add the GPG key for the Nginx repository using the curl utility in the sources list directory of apt in Debian 12:

curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \

| sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

Adding GPG key for Nignx official repository on Debian 12

Next, try a dry run to check if the GPG keys for Nginx are successfully added or not. For that import the saved GPG keys in Debian:

gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg

If the run is successful you will see the public and user keys in the image below:

verifying the Nginx GPG keys on Debian

Now add the Nginx repository on Debian, here I have used the Nngix mainline repository, and the command for that is given below:

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \

http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \

| sudo tee /etc/apt/sources.list.d/nginx.list

Adding Nginx mainline version repository in Debian

If you prefer installing the stable version of Nginx on Debian 12 then add the following repository for Nginx stable version

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \

http://nginx.org/packages/mainline/debian `lsb_release -cs` nginx" \

| sudo tee /etc/apt/sources.list.d/nginx.list

 

Now add the priority for installing Nginx from the repository added previously in case there is a conflict between the package and sources. To add priority for using the Nginx repository on Debian 12 execute:

echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" \

| sudo tee /etc/apt/preferences.d/99nginx

Adding a Nignx repository as priority to install packages for Nginx on Debian

Since the repository is added to apt so to apply the changes update the packages list by executing:

sudo apt update

Updating Debian 12 packages list to add Nignx official repository .

Now install Nginx on Debian using its official repository:

sudo apt install nginx

Installing Nginx web server on Debian 12 using Nginx official repository.

Next,  check the version Nginx web server by executing the below commands :

sudo nginx

curl -I 127.0.0.1

Checking the version of Nginx installed on Debian using Nginx official repository

How to Configure Nginx on Debian 12

To start using the Nginx web server on Debian some configuration steps are need to be done to ensure its smooth functionality. First of all, check the status of the Nginx service using the systemctl utility:

sudo systemctl status nginx

Checking the status of Nginx service on Debian 12

Now here my Nginx service is already enabled but it is inactive so for that use the start command along with the systemctl utility.

sudo systemctl start nginx

activating or starting the Nginx service on Debian using systemctl start nginx

The next thing you need to do is to allow the Nginx web server from the Debian 12 firewall so for that first install the firewall on Debian by executing the below command:

sudo apt install ufw

The firewall on Debian does not come pre-installed however if you have already set up the firewall then skip this step and the next one:

Installing firewall on Debian for Nginx configuration.

Now check the status of the firewall to see if it is active or not. If not then enable it. Use the below commands for this purpose:

sudo ufw status

sudo ufw enable

 checking the status and enabling the firewall on Debian for Nginx webserver.

Next, allow the Nginx HTTP through the Debian firewall as it will allow access for incoming connections that are trying to reach your Nginx server using the HTTP protocol (usually port 80):

sudo ufw allow 'Nginx HTTP'

Allowing the Nginx HTTP or port 80 through Debian 12 firewall.

Now to verify if your Nginx server is working on Debian open up your internet browser and enter your Debian 12 IP address in the address bar of the browser:

http://[enter-your-Debain-ip-address]

Verifying if Nginx is configured on Debian using system IP address

Conclusion

Nginx on Debian can be installed by two methods one by using the default package manager and the other by using the Nginx official repository. The official repository provides two versions one is mainline and the other is the stable version. The mainline version is relatively new as compared to the version by the Debian 12 apt package manager. To activate Nginx on Debian add its port to the firewall.

 

Index
Scroll to Top