How Can We Help?

How to install NGINX in Ubuntu 18.04 LTS

Table of Content

What is NGINX?

NGINX has powerful load balancing, reverse proxy and cache features, an open-source web server. It was first designed to solve problems of scaling and competition with existing Web servers. Its asynchronous event-based architecture has made it one of the most famous web servers available and the most efficient.

Before You Begin

1. Configure your Cloud server in your Server Guides to get started and secure.

2. You can configure this using our DNS Manager Guide if you want a custom domain name for your site.

Do not forget to update the public IP and fully qualified domain name of your Site, as explained in the Getting Started Guide section of the Update Hosts of your System File.

Install NGINX

Currently, it is best to use version in the repositories of Ubuntu to install NGINX on Ubuntu 18.04 LTS:

sudo apt update
sudo apt install nginx

Add a Basic Site

1. Build a new website directory. Substitute abc.com for the domain name of your site.

sudo mkdir /var/www/abc.com

In your /var/www/abc.com directory, you can add your website files. Create an index file using a simple example of "Hello World." Create a new file, /var/www/abc.com/index.html.  with your preferred text editor. Substitute abc.com  with the domain name or the public IP address of your cloud server.

/var/www/abc.com/index.html

Microhost Cloud

Configure NGINX

The configuration files NGINX-specific to the site are kept available under /etc/nginx/sites-available  , symlinked to /etc/nginx/sites-enabled/. Generally, for every domain or subdome you host, you want to create a separate original file in the directory available for the sites, and then you set up a symlink to the directory with the sites-enabled.

1. Deactivate the default setup file by removing the /etc/nginx/sites-enabled/ symlink:

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

2. In your chosen text editor, create a configuration file for your site. Replace abc.com  with your site domain name or IP address in the server_name  directive:

/etc/nginx/sites-available/abc.com

server {
listen 80;
listen [::]:80;
server_name abc.com;

root /var/www/abc.com;
index index.html;

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

}

3. To allow your configuration, establish an additional symlink to the /etc/nginx/sites-enabled/  directory:

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

Test NGINX

1. Test your configuration for errors:

sudo nginx -t

2. Retrieve the settings:

sudo nginx -s reload

3. Browse the domain name or IP address on your cloud server in your browser. You ought to see your simple page shown.

Thankyou..

Table of Contents