How to Install Nginx on Debian 11

Install Nginx on Debian 11

In this article, we will have explained the necessary steps to install the Nginx on Debian 11. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Nginx is one of the most widely used web servers in the world and can be used to host simple websites or also as a reverse proxy, mail proxy, and/or HTTP cache system. In addition to this, it can be used as a Load Balancer and as a reverse proxy for our web applications.

Install Nginx on Debian 11

Step 1. The first command will update the package lists to ensure you get the latest version and dependencies.

sudo apt update
sudo apt upgrade

Step 2. Install Nginx web server on Debian system.

You can install Nginx along with any other required dependencies using this command:

sudo apt install nginx

The Nginx service will start automatically at the end of the installation. So you can get the service started by running:

sudo systemctl status nginx

Verify installed Nginx version:

nginx -v

Step 3. Nginx Configuration File’s Structure.

  • Nginx configuration files are stored in the /etc/nginx directory.
  • The main Nginx configuration file is /etc/nginx/nginx.conf.
  • Server block (vhost) configuration files are stored in /etc/nginx/sites-available a directory. The configuration files found in this directory are used by Nginx only when linked to the /etc/nginx/sites-enabled directory.
  • To activate a server blocks create a symlink (a pointer) from the configuration file in a sites-available directory to the sites-enabled directory.
  • To write more maintainable code, it’s a good idea to follow a standard naming convention. For example, if your domain name is mydomain.com then the configuration file should be named /etc/nginx/sites-available/mydomain.com.conf.
  • Nginx log files (access.log and error.log) are located in the /var/log/nginx/ directory. It is recommended to have a different access and error log files for each server block.

Step 4. Install PHP with Nginx on Debian 11 Bullseye.

Unlike Apache, Nginx doesn’t have built-in support for processing PHP files. You’ll need to use the PHP FPM (“fastCGI process manager”) service to handle the PHP files. Now install the PHP and PHP FPM packages by running the following command:

sudo apt update
sudo apt install php php-fpm

Step 5. Configuring Firewall.

Before we can test Nginx, we need to configure your firewall software to allow access to the service:

sudo ufw allow 'Nginx Full'

Step 6. Accessing Nginx from Browser.

Once complete step-by-step installation, open a web browser and go to http://ip-address and you will see the following welcome screen.

Install Nginx on Debian 11

That’s all you need to do to install the Nginx on Debian 11 (Bullseye). I hope you find this quick tip helpful. For further reading on Debian’s system, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.