In this POST we will look, how we can install Nginx on Ubuntu and host one small website on Nginx.
Nginx is an open-source application which is used as web serving, reverse proxy, load balancing, media streaming and many more.
Nginx is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.
Source code of Nginx is in C language and works on port 80. You can visit the official website.
QUICK view to installing Nginx on Ubuntu
After the Quick view please read the POST to get the detailed Knowledge about the hosting in Nginx.
Install and configure Nginx on Ubuntu.
STEP 1: Update the package using apt command.
$ sudo apt update
So, we have update repository with the help of above command now we will install Nginx package.
STEP 2: Install Nginx package using apt command.
$ sudo apt install nginx
This will install the Nginx package and then it start the Nginx service also, you can check the status by using below command.
$ sudo systemctl status nginx
If you want to start the service then use start in the place of status.
$ sudo systemctl start nginx
And if you have to stop the service then use stop in the place of status, this will stop the service of the Nginx.
$ sudo systemctl stop nginx
If you have made any changes in the configuration file then you can reload the Nginx by using below command.
$ sudo systemctl reload nginx
Suppose you have to start and stop the service of Nginx then use restart.
$ sudo systemctl restart nginx
STEP 3: Check the IP and put that into the browser to get the Nginx Page.
Command for IP $ ip a
You can see the red highlighted part in the above image that is our IP “192.168.0.105”.
So we got the Nginx Page, lets have a look at the Nginx configuration files.
So the configuration folder is “/etc/nginx” and in that the highlighted part is the configuration file and folder.
STEP 4: Host our own website in Nginx.
So the folder is “/var/www/html” in which we will host our website, but first, we will delete the files and folder in that directory.
Command $ sudo rm -rf *
This will delete all the folder and files in the /var/www/html directory.
Create one file named as “index.html” and we will write some basic html code.
<h1>Welcome to Tastethelinux!!!</h1> <title>Learn and grow with Technology</title>
Just save and quit the file and refresh the browser and you will see your website. You can see the title and the heading in the HTML code
Learn about the cd command used in this POST.