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
root@test:~# 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.

host a website on ubuntu 20.04host multiple websites on one server nginxinstall nginx on ubuntuinstall nginx on ubuntu 20.04nginx server block ubuntu 20.04nginx tipsubuntu tips
Comments (0)
Add Comment