How to Install Nginx on Debian 10

Install Nginx on Debian 10

In this article, we will have explained the necessary steps to install and setup 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.

Install Nginx on Debian

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

Step 2. Install Nginx.

The Nginx package is included in the default Debian Buster repositories. Run following command to install Nginx:

Once it is installed, start and enable the Nginx service by typing:

To verify that the service is running, check its status:

Step 3. Configure Firewall.

UFW users can open HTTP (80) and HTTPS (443) ports by enabling the ‘Nginx Full’ profile:

Step 4. 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 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.
  • The /etc/nginx/snippets 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 (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 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.