Hey, everyone.
And welcome back.
Now in today's video, we'll go ahead and launch the infrastructure which is required for installing
Nginx.
Now, just to revise to begin the Nginx installation process.
What we need, we need one virtual machine with the operating system of either CentOS eight or Rocky
Linux eight.
Once we have our VM available, we'll go ahead and install Nginx on top of it.
Now whenever you create a new Linux virtual machine, there are multiple ways in which you can log in
to the server.
The first one is the password based authentication.
So this is the simplest approach where you specify the username and you specify the password to connect
to the Linux server.
So although this is good, but it is not really recommended specifically, if you have your server over
the internet, you will observe that in case if you have a server over the internet and the SSH port
is open for everyone, within just few days you will have thousands of brute force attempts from the
attackers who are trying to hack into your server based on the password based authentication.
So this is one of the primary reasons why do not enable password based auth for a Linux server on the
internet.
It has also been observed that many users also write down their passwords in notepad files or maybe
even in sticky notes.
So in case if their workstation is breached, the attacker can easily fetch the password from the plain
text files.
So this is one important part to note.
So now what is the alternative?
The alternative and also the recommended way is to make use of the key based authentication.
And this is one of the common ways in most of the organizations as well.
So what happens in key based authentication, there are two keys that are generated.
First one is a public key.
Second one is the private key.
So this public key is stored in your Linux server.
And whenever you want to log in to the Linux server, you need to have this private key as well.
So just to revise you have a public key which is stored on the Linux server and when you want to log
in to the Linux server, you will also have to make use of the private key which is stored in your laptop
in order to successfully authenticate in case if you do not have this private key, you will not be
able to log in.
And this private key, as the name suggests, needs to be private.
So this is something that you will not share with anyone.
So now for this video, what do we need?
We need to first create a public key and a private key.
And then we also need to make use of a Linux virtual machine.
So these are the two resources that we will be creating in today's video.
So currently I am within the digital ocean environment and within your you have a resource of droplet.
So droplet is nothing but a virtual machine.
So depending upon the provider that you use in AWS, it is referred to as EC2 or in maybe generic terms,
you can just call it as a virtual machine.
In digital ocean it is referred to as a droplet.
So all of these are the same thing.
So all you can go ahead and do is you can create a new droplet here or to be precise, a new virtual
machine here.
The first important part is you have to select a right operating system image.
We will be making use of a rocky Linux image based on the major version of it.
The second one is you have to choose a plan.
Again, there are multiple CPU options.
Let's use the cheapest one, which is the regular Intel with SSD, which costs around $5 per month.
Basically, this is an hourly cost.
So even after ten hours you terminate your VM, you will only be charged for ten hours.
The next important part is you will have to choose a data center region so you can choose any data center
which is closest to your location.
And the next important part, as we were discussing, is the authentication.
You can either use SSH keys or you can even make use of a password based authentication where you will
have to supply the password that you want to use while logging in.
However, this is something that we will not be using.
We'll be using the key based authentication here.
Now again, you see that we have multiple keys available, so basically each key is for a different
course.
So we have a Docker key for Docker core, Splunk key for Splunk, course console key for console course.
And we also have a Kubernetes key available.
So what we'll be doing, we'll be creating a new key altogether.
And at this stage you will have to create a new public private key.
So creating a new public private key is extremely simple.
All you will have to do is you will have to specify the command of SSH keygen.
So this works in Windows 10 as well, and SSH client comes default in Mac OS and even Linux.
So if you are using Mac or Linux, you do not really need to worry at all.
So once I press enter it is stating generating public private key.
And here you have to specify the path in case if you would not like you can just press enter and the
key will be created.
Now I'll be specifying the path here.
So let me copy this up.
Let me paste it.
And this is the name of the key.
So let me just call it as Enginex key.
I'll press enter.
You can specify the passphrase as well.
However, just for simplicity, this is something that I'll avoid.
Let's press enter again.
And now you see we have our private key and our public key that is created in this specific location.
Now, one more important thing specifically for Windows users in case if you see that when you run SSH
key gen, it says command not found specifically for Windows 10, that means the SSH is not really enabled.
So basically what you need to do, you can just look into the app features.
So for app and features here.
You have optional features and within here you can just search for search.
So you have a openssh client in case if it is not enabled, you can go ahead and enable it right away.
Now for the users who are using an older version of operating system of Windows, you can also make
use of a tool like Mobaxterm.
So within Mobaxterm also if you just type SSH key gen, you see it works perfectly well similar to what
we are seeing in Windows CLI.
Now going into the directory where our public private key are created, so you should see that there
are two keys.
One is the Nginx public key and the nginx private key.
And the public key is what will be stored at a server level.
So let's quickly open the public key here.
Let's open up with atom editor or you can even open it up with the notepad.
So this is how the public key really looks like.
Let's copy this up.
And within our environment, I'll just paste the public key here and the name, let's just call it as
nginx key, and I'll quickly add an SSH key here and within choose your SSH keys, you will have to
select the new key that you have created.
And if you go a bit down, the next important part is how many virtual machines you want to create.
Currently we only need one VM, so I'll just select one droplet in case.
If you need multiple virtual machines you can just increment it accordingly.
However, to begin with, let's keep it simple and the name that we will give, let's just call it as
Demo Nginx and you can go ahead and click on Create Droplet.
However, before we just do that, let's verify the plan that we have selected.
So currently here you see we have a $40 per month plan.
We do not need it.
We'll be using the $5 per month plan.
This is more than enough.
And with the credits, you do not really even have to pay this.
Great.
So once you have done it, you can go ahead and create a new droplet.
Great.
So a new virtual machine is getting created so it can take around 2 to 3 minutes for the VM to be created
here.
So let's quickly wait for a moment here.
Great.
So it took around two minutes and our new virtual machine is up and running.
It is also giving us the public IP.
So let's quickly copy the public IP here.
And from a CLI, let's quickly go to this specific directory where our key is created.
So it is C drive users Zalora and we need to go to the SSH directory where our key is created.
So now under this directory, if I do a dir in the case of Mac or Linux it should be LS.
You should see that there are multiple keys.
We are primarily interested in this nginx key.
So basically this is the location where our key is stored.
So in this location, let's go ahead and connect to the server.
So I'll specify the name of the key.
In this case it is nginx key and then you'll have to specify the username on the server side.
So in case of rocky Linux the username is root in case.
If you are making use of maybe CentOS then the username would be CentOS.
So depending upon the cloud provider that you choose, the default username might change accordingly.
In case of the AWS, the username might be EC2 user and so on.
So I'll be specifying root followed by the IP address of the new server that we have created.
I'll press enter.
Let's do a yes.
All right.
So it is stating permission denied.
No such file or directory.
So this is primarily because of the typo.
The name of the key is nginx underscore key.
However, here we have specified nginx hyphen key.
So let's go ahead and change this to nginx underscore key.
All right.
So now you see we are connected to our server.
Again, just to reiterate, depending upon the cloud provider that you choose and the operating system
that you choose, this default username might change for CentOS.
In case if Root is not working for CentOS, you can try this username of CentOS.
And in case of AWS, you can also try the username of EC2 hyphen user primarily because in AWS EC2,
the root username is disallowed by default.
The next important part is the firewall rule.
So ideally you should have two firewall rules allowed.
First one is the SSH connection from your ISP and the second one is port 80 should be allowed because
Nginx would typically listen on port 80.
So these are the two important rules that should be allowed in case if you are making use of digitalocean
there is nothing to worry because by default the firewall is not really associated, so all the connections
are allowed to the server.
However, for AWS, this is not the case.
You will have to create a new security group with these two ports that should be allowed in case.
If you would also like, you can also restrict these two ports to your ISP IP address.
However, we'll just keep it simple.
And this is more of a informational purpose in case if you are using a different cloud provider.
Great.
So our base infrastructure for Nginx is up and running.
So in the upcoming video, we'll go ahead with the installation of Nginx post which will be discussing
about great features of Http and Nginx as a whole.
So with this we'll conclude today's video.