How to Install Nginx on Debian 10 Buster

2542
Share:
how-to-install-nginx-on-debian-10-buster

Nginx (pronounced "engine X"), stylized as NGINX, nginx or NginX, is an open-source, high-performance HTTP and reverse proxy server that powers some of the largest sites on the Internet. Compared to Apache, Nginx can handle a much large number of concurrent connections and has a smaller memory footprint per connection.

It was created by Igor Sysoev and publicly released in 2004. Nginx is free and open-source software, released under the terms of the 2-clause BSD license. Nginx can be used as a standalone web server, and as a reverse proxy for HTTP and non-HTTP servers.

In this article, we’ll discuss how to install Nginx on your Debian 10 Buster.

Before you begin this guide, you should have a regular, non-root user with sudo privileges configured on your server.

Nginx Installation

As usual, since this is our first interaction with the apt packaging system in this session, let’s first update our local package index so that we have access to the most recent package listings:

$ sudo apt update

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 install nginx

When prompted to confirm the installation, hit Enter to proceed. After that, apt will install Nginx and any required dependencies to your server. Nginx service will automatically start after the installation process is complete. You can verify it with curl as shown below:

The output will look similar to this:

HTTP/1.1 200 OK
Server: nginx/1.14.2
Date: Sat, 20 Feb 2021 07:56:08 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sat, 20 Feb 2021 07:48:22 GMT
Connection: keep-alive
ETag: "6030bec6-264"
Accept-Ranges: bytes

Firewall Setting

If you have ufw installed on your server, you need to update it. First, let's figure out what options are available:

$ sudo ufw app list

It will respond with something like this:

Available applications:  
...
Nginx Full
Nginx HTTP
Nginx HTTPS
...

As you can see, there are three profiles available for Nginx:

  • Nginx Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Nginx HTTP: This profile opens only port 80 (normal, unencrypted web traffic)
  • Nginx HTTPS: This profile opens only port 443 (TLS/SSL encrypted traffic)

For the sake of testing, let's use Nginx Full option:

$ sudo ufw allow 'Nginx Full'

We can verify the change by typing:

$ sudo ufw status

You should see HTTP traffic allowed in the displayed output:

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere                  
Nginx HTTP                 ALLOW       Anywhere                  
OpenSSH (v6)               ALLOW       Anywhere (v6)             
Nginx HTTP (v6)            ALLOW       Anywhere (v6)

Otherwise, if you're using nftables for your firewall application, let's allow Nginx to access port 80 and 443:

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

Verify Installation

At the end of the installation process, Debian 10 starts Nginx. The web server should already be up and running.

We can check with the systemd init system to make sure the service is running by typing:

$ sudo systemctl status nginx

The output should be similar with below:

● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-02-20 07:48:32 GMT; 21min ago
Docs: man:nginx(8)
Main PID: 3125 (nginx)
Tasks: 2 (limit: 4915)
Memory: 2.8M
CGroup: /system.slice/nginx.service
├─3125 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─3126 nginx: worker process

Feb 20 07:48:32 natrium.r00t4bl3.com systemd[1]: Started A high performance web server and a reverse proxy server.

Nginx Process Management

We can use any systemctl to manage Nginx process, just like another systemd-based services.

The syntax is below:

$ sudo systemctl <command> nginx

Where command is one of below:

  • stop - to stop Nginx service
  • start - to start Nginx service
  • restart - to stop and start Nginx service again
  • reload - to reload Nginx configuration file without dropping connections
  • disable - to disable loading Nginx service at boot time
  • enable - to enable loading Nginx service at boot time
  • status - to get Nginx service status

Final Words

I hope that you now know how to install nginx on Debian 10 Buster. If you run into any issues or have any feedback feel free to drop a comment below.

Tags Linux
Share:

0 comment

Leave a reply

Your email address will not be published. Required fields are marked *