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:
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:
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:
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:
To check Nginx configuration for errors and correct them if necessary, run the command below:
sudo nginx -t
You should receive the following output:
To configure Nginx web server to start on boot, run:
sudo systemctl enable nginx
You should receive the following output:
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:
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:
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!"
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.