How to Install Nginx on Debian 10.

How To Install Nginx On Debian 10.

In this tutorial, we’ll explain how to install and manage Nginx on Debian 10 Buster.

Install Nginx

The Nginx package is included in the default Debian Buster repositories. The installation is pretty straightforward, just run the following commands as root or user with sudo privileges :

sudo apt update
sudo apt install nginx

Nginx service will automatically start after the installation process is complete. You can verify it with curl as shown below:

curl -I XX.XX.XX.XX

You can use the systemctl command to manage the Nginx service , same as any other systemd unit.

Adjust the Firewall

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

sudo ufw allow 'Nginx Full'Copy

If you are using nftables to filter connections to your system, open the necessary ports by issuing the following command:

nft add rule inet filter input tcp dport {80, 443} ct state new,establ

Nginx Configuration File’s Structure and Best Practices

  • 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.

  • You can set your domain document root directory to any location you want. The most common locations for webroot include:

    • /home/<user_name>/<site_name>

    • /var/www/<site_name>

    • /var/www/html/<site_name>

    • /opt/<site_name>

Conclusion

Installing Nginx on Debian 10 is a matter of running a single command.

Now that you have installed Nginx on your Debian 10 Linux you can to start deploying your applications and use Nginx as a web or proxy server.