July 29, 2021
how to install nginx web server on Ubuntu 20.04

How to Install Nginx Web Server on Ubuntu 20.04

Nginx is an open-source and high-performance web server, which is mostly used in hosting high traffic websites. It can also be used as a load balancer, reverse proxy, mail proxy, and HTTP cache. This software was created by Russian software engineer Igor Sysoev and publicly released in 2004.

In this guide you will learn how to install Nginx web server and configuring the Virtual host for your application.

So, lets start with the installation process:-

  1. Updating Ubuntu packages lists:-
 sudo apt update

2. Install Nginx webserver by the following command:

sudo apt install nginx

When prompted press ‘Y’ to install the Nginx web server.

3. Verify Nginx webserver is running or Not by the following command.

sudo systemctl start nginx
sudo systemctl status nginx
[email protected]:~# sudo systemctl status nginx
● 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-01-23 08:01:05 CET; 3 days ago
       Docs: man:nginx(8)
   Main PID: 60217 (nginx)
      Tasks: 2 (limit: 2286)
     Memory: 1.0G
     CGroup: /system.slice/nginx.service
             ├─60217 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             └─60218 nginx: worker process

Jan 23 08:01:05 test systemd[1]: Starting A high performance web server and a reverse proxy server...
Jan 23 08:01:05 test systemd[1]: Started A high performance web server and a reverse proxy server.

The output above indicates that the Nginx webserver is up and running successfully.

4. To verify nginx version use the following command.

 sudo dpkg -l nginx

The output will indicates which version of Nginx web server you are using.

Configuring Virtual Host for hosting applications in Nginx Web Server

If you are planing to host your application on Nginx webserver then you can follow the following steps its very simple and easy to do.

  1. Open your Nginx webserver configuration
vi /etc/nginx/nginx.conf 

Copy and paste the following configurations

server {
        listen 80;
        listen [::]:80;

        root /var/www/html/test;
        index index.html index.htm;

        server_name test.vexplains.com;

        location / {
                try_files $uri $uri/ =404;
        }
}

Save and exit by pressing [Esc] shift to the command mode and press :wq and hit [Enter]

2. Verify Syntax error by using the following command.

nginx -t

3. Inorder to effect the changes, restart Nginx web server.

systemctl restart nginx

Now the Nginx web server will serve your domain website content.

Now, you have successfully installed your Nginx webserver and also configure the virtual host. If any doubt please comment.

Vedant Singh

Linux System Administrator | Entrepreneur | Founder Techmion. I have started my career as a Linux system Administrator after that quit my job to start something new that excites me and started a Tech Company in order to provide the best technology to my clients. My Company website link: https://www.techmion.com/ For Bulk, SMS-Marketing follows the link : https://www.pingsms.in/

View all posts by Vedant Singh →

Leave a Reply

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

close

Ad Blocker Detected!

VEDANT EXPLAINS
We've noticed that you are using an ad blocker. Advertising helps fund our server cost and keep it truly independent. It helps to build our content creator team. So please disable your ad blocker, and help us to keep providing you with free- great content - for free. Thank you for your support.

Refresh