How to install Nginx on Debian 10 Linux

Nginx is an open source, high-performance HTTP server and reverse proxy, provides support for some of the largest sites on the Internet. Compared with the Apache, Nginx can handle a large number of concurrent connections, and each connection footprint smaller.

Nginx can be used as a standalone Web server, it can also be used as HTTP and non-HTTP reverse proxy server.

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

Install Nginx

Nginx package included in the default Debian Buster repository. Installation is very simple, just run the following command with sudo privileges as the root user or users:

sudo apt update
sudo apt install nginx

After the installation process is complete, Nginx service will start automatically. You can use curl verify it as follows:

curl -I 127.0.0.1

The output looks like this:

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Tue, 16 Jul 2019 16:50:46 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 16 Jul 2019 16:50:26 GMT
Connection: keep-alive
ETag: "5d2e0052-264"
Accept-Ranges: bytes

You can use this command to manage Nginx systemctl service, like any other systemd unit.

Adjust the firewall

UFW user may open the HTTP (80) and HTTPS (443) by enabling 'Nginx Full' Port Profile:

sudo ufw allow 'Nginx Full'

If the filter is connected to the system nftables, open the necessary ports by issuing the command:

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

Nginx configuration file structure and best practices

  • Nginx configuration files are stored in / etc / nginx directory.
  • The main Nginx configuration file is /etc/nginx/nginx.conf.
  • Server block (Vhost) profiles are stored in / etc / nginx / sites-available directory. Only when linked to the / etc / nginx / sites-enabled directory, Nginx before using the configuration file in this directory.
  • To activate the server block, create a symbolic link (pointer) from the directory sites-available configuration file to the sites-enabled directory.
  • To write more maintainable code, follow the standard naming convention is a good idea. For example, if your domain name is, mydomain.com should be named profile /etc/nginx/sites-available/mydomain.com.conf.
  • The / etc / nginx / snippets directory contains configuration fragment may comprise blocks of the file in the server. If a repeatable configuration segments, these segments may be reconstituted into segments and the segments containing the file to the server block.
  • Nginx log file (the access.log and the error.log) located at / var / log / nginx / directory. It recommended There are different access and error log files for each server module.
  • You can document root domain will be set to any desired location. The most common location webroot include:
    • /home/<user_name>/<site_name>
    • /var/www/<site_name>
    • /var/www/html/<site_name>
    • /opt/<site_name>

in conclusion

Nginx install on Debian 10 is a problem running a single command.

Now that you have installed Nginx on Debian 10 Linux, you can start deploying applications and Nginx as a Web server or proxy.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159872.htm