In this tutorial, we will show you how to install nginx web server on Debian 11. Nginx is a popular web server that can be used as a reverse proxy and load balancer for your servers. It can also work as a standalone server or in conjunction with another application server. In order to make use of its functionality, we need to first install it.

Prerequisites

  • A server running Debian 11
  • You should have a regular, non-root user with sudo privileges configured on your server. This is required for the installation process to work properly.

Updating the system

Before installing nginx, you need to update the system so that it is up to date. You should also install additional required packages needed for compiling third party modules. Run the following commands to update the system and install the required packages:

sudo apt update -y
sudo apt upgrade -y
sudo apt install curl gnupg2 ca-certificates lsb-release

You should receive the following output:

<img alt="debian 11 update" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/debian_11_update.png6156da1b52a4c.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”659″>

<img alt="debian 11 update" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/debian_11_update_3.png6156da1b7fe70.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”659″>

Installing Nginx on Debian 11

Nginx is available in the default repositories of Debian 11. You can install it with apt-get command as follows:

sudo apt install nginx -y

You should receive the following output:

<img alt="install nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/install_nginx.png6156da1ba4cc1.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”659″>

<img alt="install nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/install_nginx_2.png6156da1bd5103.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”659″>

You should already have an Nginx web server up and running. You can test this by running the following command:

sudo systemctl status nginx

The output of the command above should be information about your Nginx server. You will also see a line saying Active: active (running). That means that your nginx server is successfully running.

Sample output:

<img alt="status nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/status_nginx.png6156da1c07899.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”658″>

You can start, stop and restart Nginx by typing:

sudo systemctl start nginx
sudo systemctl stop nginx
sudo systemctl restart nginx

You can check the version of Nginx installed by typing:

sudo nginx -v

You should receive the following output:

<img alt="nginx version" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/nginx_version.png6156da1c2cd47.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”658″>

To check Nginx configuration for errors and correct them if necessary, run the command below:

sudo nginx -t

You should receive the following output:

<img alt="checking Nginx configuration debian 11" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/checking_nginx_configuration.png6156da1c50bf9.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”658″>

To configure Nginx web server to start on boot, run:

sudo systemctl enable nginx

You should receive the following output:

<img alt="enable nginx" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/enable_nginx_on_boot.png6156da1c75c2d.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”658″>

Adjust The Firewall Rules

Nginx must be enabled through the firewall software before it can be accessed.

List the application configurations that have already been set up by typing:

sudo ufw app list

You will get the following output:

<img alt="ufw app list" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/ufw_app_list.png6156da1ca0e0a.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”658″>

You can see that there are three profiles that Nginx can be configured with:

  • Nginx Full: This profile opens both port 80 and 443 for Nginx
  • Nginx HTTP: This profile opens only port 80 for Nginx
  • Nginx HTTPS: This profile opens only port 443 for Nginx

It’s recommend to enable the most restricted profile so that the configured traffic can still travel through the firewall. For this guide, we will allow only HTTP traffic on port 80. To do this, type:

sudo ufw allow 'Nginx HTTP'

Run the command below to verify HTTP is allowed through the firewall:

sudo ufw status

As you can see in the output below, HTTP traffic is allowed:

<img alt="ufw status Nginx debian 11" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/ufw_status.png6156da1cccd69.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="386" loading="lazy" src="data:image/svg xml,” width=”658″>

Accessing Nginx Web Server

You can access the default Nginx landing page by typing your server’s public IP address or FQDN into your browser. If you do not know your server’s public IP address, you can find it by typing:

hostname -I

You will get an output with your server’s IP address.

Once you have your server’s IP address, type it into the browser:

http://your_server_ip

You should see a default landing page for Nginx which says “Welcome to nginx!”

<img alt="default Nginx landing page" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/10/echo/nginx_default_page.png6156da1d036da.jpg" ezimgfmt="rs rscb5 src ng ngcb5" height="274" loading="lazy" src="data:image/svg xml,” width=”716″>

Congratulations! You have successfully installed Nginx on Debian 11.

Conclusion

This was a tutorial on how to install the Nginx web server on Debian 11. We covered the basics of what it is, installation, and some basic configuration options. We hope you found this helpful.

If you want to learn more about Nginx and how it works, we highly recommended checking out the official documentation.