Install Nginx on Debian 11

This simple guide will take you through how to install Nginx on Debian 11. NGINX is a free, open-source, high-performance HTTP server. It can also serve as a reverse proxy, load balancer, as well as an IMAP/POP3 proxy server.

Install Nginx on Debian 11

Debian 11 default repositories do provide Nginx packages;

apt-cache policy nginx
  Installed: (none)
  Candidate: 1.18.0-6.1
  Version table:
     1.18.0-6.1 500
        500 bullseye/main amd64 Packages

However, the current stable release version of Nginx, as of this writing, is v1.20.1.

Thus to install latest Nginx on Debian 11;

Install Nginx Official APT Repository on Debian 11

Install Required Dependencies

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

Import official Nginx repository signing key;

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

Validate the imported key by running the command below. Ensure that the output of the command contains the key, 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62.

gpg --dry-run --quiet --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
pub   rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
uid                      nginx signing key <[email protected]>

Next,  install apt repository for stable nginx packages;

echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \ `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list

Next, set the Nginx official repositories to take precedence over the default Debian 11 repositories for the installation of Nginx related packages;

echo -e "Package: *\nPin: origin\nPin: release o=nginx\nPin-Priority: 900\n" \
| sudo tee /etc/apt/preferences.d/99nginx

Install Nginx on Debian 11

Once the official Nginx repositories are in place, proceed to install Nginx.

Run system package update;

apt update

Install Nginx on Debian 11

apt install nginx

Verify installed Nginx version;

nginx -v

Sample output;

nginx version: nginx/1.20.1

Running Nginx on Debian 11

You can manage Nginx service using systemctl.

To start and enable it to run on boot, run the command;

systemctl enable --now nginx

Checking the status;

systemctl status nginx
● nginx.service - nginx - high performance web server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2021-08-21 22:31:21 EAT; 47s ago
    Process: 2517 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
   Main PID: 2518 (nginx)
      Tasks: 2 (limit: 1133)
     Memory: 1.7M
        CPU: 5ms
     CGroup: /system.slice/nginx.service
             ├─2518 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
             └─2519 nginx: worker process

Aug 21 22:31:21 debian11 systemd[1]: Starting nginx - high performance web server...
Aug 21 22:31:21 debian11 systemd[1]: nginx.service: Can't open PID file /run/ (yet?) after start: Operation not permitted
Aug 21 22:31:21 debian11 systemd[1]: Started nginx - high performance web server.

Accessing Nginx from Browser

Nginx is now installed. To verify that you can access it from browser, nagivate to the address http://server-ip.

To allow external access, allow Nginx on UFW, that is if UFW is already installed and enabled.

ufw allow "WWW Full"

If you get to such a page on browser, then Nginx is installed and running fine on Debian 11.

Install Nginx on Debian 11

That is all on how to install Nginx on Debian 11.

Further Reading

Nginx Documentation

Other Tutorials

Install Apache HTTP Server on Debian 11

Install Debian 11 Bullseye on VirtualBox

Install Usermin on Rocky Linux 8

Founder of|Linux Engineer|Author at

Leave a Comment