How to Install NGINX on a Debian 10 VPS

How to Install NGINX on a Debian 10 VPSThis article was contributed by the folks at RackNerd – a provider of shared hosting, reseller hosting, VPS hosting, dedicated servers, DRaaS, colocation, and more. If you are looking for a VPS with full root access to set up NGINX on, be sure to review their latest LowEndBox special offers here.

NGINX is a popular open-source HTTP web server. It is known for its high-performance and feature-rich experience. NGINX is also used as a load balancer, mail proxy, and reverse proxy. It was released in 2004 and was created by Igor Sysoev. The majority of the web utilizes NGINX, especially as a load balancer.

Today, we are going to see how you can install and configure NGINX on your Debian 10 virtual private server. Let’s start the process.

  1. Requirements

Before you start, make sure that you have root access to your server.

  1. Install NGINX

The installation of NGINX is quite simple. It is available in Debian’s repositories, and it only takes a couple of commands to install it.

Run the following code to get NGINX installed:

sudo apt update

sudo apt install Nginx

Once these commands are executed, you will have NGINX installed on your system.

  1. Create a directory for your site

Now, we need to make a directory where your website can be saved.

Create the directory with the following command, replace “example.com” with your own domain name.

sudo mkdir /var/www/example.com

  1. Add the files for your site

Now, place the files for your existing website in this directory. However, if you do not yet have a website, you can make a simple index.html file to check the NGINX installation.

Create a new file named “Index.html” and paste the following content:

<!DOCTYPE html>

<html>

<head>

     <title>Hello, NGINX</title>

</head>

<body>

     <header>

         <h1>Hello, NGINX!</h1>

     </header>

</body>

</html>

 Configure NGINX

The site-specific configurations for NGINX can be found in the “/etc/nginx/sites-available” directory. These configuration files are linked to the directory “/etc/nginx/sites-enabled/”.

We need to create a new server black in the “/etc/nginx/sites-available” directory. Though, first, we need to remove the default configuration file. Run the following command to do so:

sudo unlink /etc/nginx/sites-enabled/default

Now, we will create a new file with the name of our web site’s domain name, e.g., “check.com”.

Paste the following in to this configuration file:

server {

listen 80;

listen [::]:80;

server_name  example.com;

 

root /var/www/example.com;

index index.html;

 

location / {

     try_files $uri $uri/ =404;

}

}

We need to link this file to the “/etc/nginx/sites-enabled/” directory. Run the following command:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

  1. Test NGINX

We are done with the installation and the configuration of NGINX on our system. Now, it is time to test it.

To test the NGINX installation, run the following command:

sudo nginx -t

sudo nginx -s reload

If you now open your website in a web browser, you will be able to see the index.html page.

What is your favorite web server, is it NGINX? We would love to hear about your comments down below!

Jon Biloh

I’m Jon Biloh and I own LowEndBox and LowEndTalk. I’ve spent my nearly 20 year career in IT building companies and now I’m excited to focus on building and enhancing the community at LowEndBox and LowEndTalk.