In this tutorial, we will show you how to install Nginx Mainline Version on Debian 11. For those of you who didn’t know, Nginx is a well-known web server with open-source access and is used by top-rated companies because of its extensive support. The software is known for its low impact on memory resources, high scalability, and modular, event-driven architecture which can offer secure, predictable performance. More than just a web server, Nginx also works as a load balancer, an HTTP cache, and a reverse proxy. Since it’s free open-source software (FOSS) and high-performance HTTP web server, you can use, modify and distribute it freely without spending money at all.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Nginx mainline version on a Debian 11 (Bullseye).
- A server running one of the following operating systems: Debian 11 (Bullseye).
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install Nginx Mainline Version on Debian 11 Bullseye
Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following
apt commands in the terminal:
sudo apt update sudo apt upgrade sudo apt install curl gnupg2 ca-certificates lsb-release dirmngr software-properties-common apt-transport-https
Step 2. Installing Nginx Mainline Version on Debian 11.
By default, Nginx mainline is not available on Debian 11 base repository. So, now run the following command below to add the Nginx mainline repository to your Debian system:
echo "deb [arch=amd64,arm64 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
Next, add the GPG key using the following command:
curl -fSsL https://nginx.org/keys/nginx_signing.key | sudo gpg --dearmor | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
Set up repository pinning to prefer our packages over distribution-provided ones:
echo -e "Package: *\nPin: origin nginx.org\nPin: release o=nginx\nPin-Priority: 900\n" | sudo tee /etc/apt/preferences.d/99nginx
After the repository was added, now update the package source and install Nginx mainline package using the following command below:
sudo apt update sudo apt install nginx
Once the installation is complete, start Nginx and add it to automatically start on your system start-up using:
sudo systemctl start nginx sudo systemctl enable nginx
Check the installed version of Nginx with the help of the following command:
Step 3. Configure Firewall.
Now add firewall rules to allow connections as well as HTTP (port 80) and HTTPS (port 443) traffic:
sudo ufw allow 'Nginx HTTP'
Congratulations! You have successfully installed Nginx mainline version. Thanks for using this tutorial for installing the latest version of the Nginx web server on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official Nginx website.