In this article, we will have explained the necessary steps to install and set up Nginx on Debian 10. 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 pronounced “engine x” is an open-source, high-performance HTTP and reverse proxy server responsible for handling the load of some of the largest sites on the Internet. It can be used as a standalone web server, load balancer, content cache, and reverse proxy for HTTP and non-HTTP servers.
- Operating System with Debian 10
- Server IPv4 Address with Superuser Privileges (Root Access)
- Gnome Terminal for Linux Desktop
- PuTTy SSH client for Windows or macOS
- Powershell for Windows 10/11
- Familiar with APT Commands
Install Nginx on Debian
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.
The Nginx package is included in the default Debian Buster repositories. Run following command to install Nginx:
sudo apt install nginx
Once it is installed, start and enable the Nginx service by typing:
sudo systemctl start nginx sudo systemctl enable nginx
To verify that the service is running, check its status:
sudo systemctl status nginx
Step 3. Configure Firewall.
UFW users can open HTTP (80) and HTTPS (443) ports by enabling the ‘Nginx Full’ profile:
sudo ufw allow 'Nginx Full'
Step 4. Nginx Configuration File’s Structure.
- Nginx configuration files are stored in the
- The main Nginx configuration file is
- Server block (vhost) configuration files are stored in
/etc/nginx/sites-availablethe directory. The configuration files found in this directory are used by Nginx only when linked to the
- To activate a server blocks create a symlink (a pointer) from the configuration file in a
sites-availabledirectory to the
- To write more maintainable code, it’s a good idea to follow a standard naming convention. For example, if your domain name is
mydomain.comthen the configuration file should be named
/etc/nginx/snippetsthe directory contains configuration snippets that can be included in the server block files. If you use repeatable configuration segments then you can refactor those segments into snippets and include the snippet file to the server blocks.
- Nginx log files (
error.log) are located in the
/var/log/nginx/directory. It is recommended to have a different
errorlog files for each server block.
Step 5. Accessing the Nginx.
Now, you can test your Nginx installation, by opening http://YOUR_IP_ADDRESS or http://YOUR_DOMAIN in your web browser. You should see the default Nginx welcome page.
Congratulation, you have learned how to install and configure Nginx on Debian 10 Buster. If you have any question, please leave a comment below.