Installing a web server (nginx)

The server behind the web

Posted by Kostas Michailidis on February 27, 2024

What is Nginx?

Nginx is an open source web server used for serving websites, load balancing, reverse proxying, and other HTTP and proxy server capabilities, it is similar to the Apache web server, but for this tutorial we will focus on nginx.

Install and configure Nginx

We are going to install nginx on debian based distributions of linux in my case is debian 11.

First we open up a terminal and we are going to update the list of available packages of the system.

sudo apt update

Then we install nginx

sudo apt install nginx

We can check if nginx has started with

sudo systemctl status nginx

We should see something similar to the following

If not, we can start the server with the following command

sudo systemctl start nginx

We can also configure nginx to start when we boot the system

sudo systemctl enable nginx

If for some reason we want to disable it we can

sudo systemctl disable nginx

Then we can go to a web browser and put the local ip address of the system we are running nginx, we can also use the loopback address 127.0.0.1 if we are in the same system.

We should see the default web page of nginx if everything works.

Then we can create the directory of our web page, in my case im going to name it mytest.

sudo mkdir /var/www/mytest

After that we can create an html file with the code of our page (we must name it index.html), you can use whatever text editor you are familiar with , in my case im going to use Vim.

sudo vim /var/www/mytest/index.html

and we save it

After that we need to create a copy of the default configuration and name it after our website.

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/mytest

and we need to change the line root /var/www/html; with root /var/www/mytest;

sudo vim /etc/nginx/sites-available/mytest

and we save it

We must create a soft link to sites-enabled of the mytest config in sites-available.

sudo ln -s /etc/nginx/sites-available/mytest /etc/nginx/sites-enabled/

We remove the default web page soft link from sites-enabled.

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

and we are reloading the configuration of the server.

sudo systemctl reload nginx

We should see the following in the browser.

It's that all ?

This is a basic installation and configuration of nginx web server without ssl, which i'm going to talk more about it in the future.