So in the last chapter we were looking into the basic type of Http authentication.
So we looked into the overview on how exactly it works.
So in this video, we'll look into how we can implement Http basic authentication in Nginx.
So the very first thing that you have to verify if the Httpd Tools package is installed, because this
basically will be useful in the basic authentication.
So you can say httpd tools and you can see it is installed.
So if it is not installed, you can do yum!
Install httpd tools and this will be good enough.
So we have two pages, so I'll show you the configuration.
So here we have two location directives.
One is location for root and one is admin page.
Now we have already discussed admin page contains secret data, so this is something that we want to
have an authentication for.
So if I go to the browser and let me open example.com slash admin and here you see the admin page is
not protected.
So let's use the Http basic authentication and protect this particular page.
So within the admin location directive, because this is where we actually want to protect our page,
we'll say auth underscore basic.
Followed by the name that you can give any name.
I'll say basic authentication.
So this becomes the realm.
Followed by the odd underscore basic user.
Let's take it.
Enginex dot Password.
So basically the first.
Line signifies that this is going to be basic authentication and for server to verify the password and
username is correct.
This is a particular file.
So in nginx dot password the username and password will be stored.
So I'll just save it.
And this is nginx directory.
So let's create our own password file.
Password.
See.
And it is.
Say is the password.
C stands for create a new file.
We also have to specify the username.
So let's say username is admin.
Oops.
It's the password.
So for admin it is asking me for a password.
I'll say password and it created a password.
So if I do a cat password file, you see there is an admin followed by the password associated with
it.
So let's verify if the nginx configuration changes are successful.
And it is.
So let me reload the nginx.
And let's open the.
Browser and let's refresh.
And now you see it is asking for username and password when we go to slash admin.
So this is basically how basic authentication in Http is implemented.
So again, if you want to implement basic authentication, always try to use it along with the Https
or SSL.
Otherwise, this is a big security vulnerability.
So I hope this lecture has been informative for you and I'd like to thank you for viewing.