fbpx
nginx

How to install Nginx on Ubuntu.

ubuntu

A common topic for beginners on how to host a simple HTML website in Nginx. I am a great fan of Nginx for its capability, performance, and simplicity.

Let’s go through some insights including installation and path structure.

INSTALL NGINX ON UBUNTU:

1sudo apt update
1sudo apt install nginx

That’s it! Thanks, Ubuntu keeping Nginx in its apt repository.

ENABLE NGINX ON FIREWALL :

 
firewall

We need to allow Nginx to use HTTP [port 80] at the firewall.

If you are using Server instances from AWS, they have a security layer that acts as a security firewall. you might have noted something like configuring  `Security Groups`  this while creating an instance in AWS. In that case, altering ubuntu’s built-in firewall [ command ‘sudo ufw [options]‘]  might cutdown ssh access to the server. So my suggestion is if you are not sure what’s going to happen, just ignore `​ufw` commands in servers.

To view list of applications which request for the port, run  :

1sudo ufw app list

After installing Nginx, this command will return something like:

12345Available applications:Nginx FullNginx HTTPNginx HTTPSOpenSSH

enable Nginx HTTP access by.

1sudo ufw allow 'Nginx HTTP' # for allowing port 80
1sudo ufw allow 'Nginx HTTPS' # for allowing port 443
1sudo ufw allow 'Nginx Full' # for allowing port both together

View the list of allowed applications.

1sudo ufw status

If the terminal shows Status: inactive that means the firewall is off. you do not have to bother about them. Else the output will be something like.

12345678Status: active To                         Action      From--                         ------      ----OpenSSH                    ALLOW       Anywhere                  Nginx HTTP                 ALLOW       Anywhere                  OpenSSH (v6)               ALLOW       Anywhere (v6)             Nginx HTTP (v6)            ALLOW       Anywhere (v6)
 

VERIFICATION :

When an application is put in daemon mode, ubuntu has some built-in monitoring applications. systemd,  service,  init.d e.t.c. My favorite is service.

1sudo service nginx status

This will output something similar to:

● 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 Fri 2019-12-13 10:09:53 IST; 5h 1min ago
     Docs: man:nginx(8)
  Process: 1416 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 1503 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 1505 (nginx)
    Tasks: 5 (limit: 4915)
   Memory: 7.1M
   CGroup: /system.slice/nginx.service
           ├─1505 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           ├─1506 nginx: worker process
           ├─1507 nginx: worker process
           ├─1508 nginx: worker process
           └─1509 nginx: worker process

Now go to browser and open `http://localhost` or `http://<ip.address>` or `http://<domain.name>` to open nginx home page.

CONTROL:

Stop, Start or Restart by :

1sudo service nginx <stop|start|restart>

Know Server Status by :

1sudo service nginx status

While installing,  Nginx will be already registered to OS services, with the “start Nginx on boot” option as enabled.

1sudo service nginx <enable|disable>

    Get a Free Quote





    Book a 30 mins

    Free Consultation

    Call With Us!