What's going on guys it is Bernardo from the BTNHD and today is all about configuring a
virtual host in nginx, so let's get right into it alright so creating a virtual host.
Awesome.
Like I said before, and when I did the installation part of nginx within Ubuntu this is all new
to me I'm learning as I go and I'm pushing it out to you guys if you guys have any tips
and tricks with this new platform, leave it at the comment section because I am always
willing to learn.
So, how to create a virtual host or how I taught myself how to create a virtual host.
Now within terminal I ran the command of sudo Su, I wanted to give myself root access so
I don't have to always type in sudo, and then the command, right.
So I hit Enter, provided the password, boom, now I'm logged in as root next command that
I'm going to run is the following.
I want to get into the directory of sites enabled.
And once I'm in there I'm going to run LS to list the directory, I want to unlink this
default site.
And to do that, we're going to run the following command of unlink default.
Hit enter.
Now if you run the following command of LS to look at the directory, you're going to
see that it's not there anymore.
But, don't freak out because default is still there.
If you've run the following command to change the directory to go inside site available,
you hit Enter, and then you run the following command of LS, and you hit enter, is going
to show you that the default is still there, right and then go anywhere.
Now we're going to run the following command of nano, and we want to create our virtual
hosts.
Now the virtual host a configuration file I called it as BTNHD site dot local dot nconf,
I hit Enter.
And from here I'm going to type in the following I'm going to call out server with the open
brackets.
Listen to Port 80, and also declare the root of where this particular website is going
to be stored, you're going to close the bracket, you're going to do a Ctrl O to write it hit
enter and then Ctrl X to exit out.
Now we're going to run the following command to just look at the content that we just created
so we're going to run cat and your file.
Hit enter.
And that's the content now next command that we are going to run, is we need to reload
our nginx so we are going to run a systemctl reload nginx, not to check the status of the
reload we can run a systemctl status nginx.
And if you look at the very bottom right there it will state reloading and it was reloaded
I next step that I'm going to do is create a directory and the directory would be BTNHD
site dot local and it's going to be placed inside the www folder.
Okay, hit enter there.
Bam.
Now, next command that we need to do is I am going to create a index file within that
directory that we just created within the www folder so super simple, right just echo
this particular string to that file and hit Enter, and you're good to go.
Now if you open up a browser and you type in localhost you hit enter, it's going to
show you the text that you kind of inserted inside the index dot HTML file for us, or
for me.
I typed in BTNHD site coming soon using nginx now within the terminal command I'm going
to run the following command, I need to get inside our virtual host.
And I'm going to hit enter here.
Now some of the changes that I'm going to do within this virtual host file is the following.
I'm going to add a default underscore server to listen to Port 80.
And I'm also going to add a server name.
So the server name is either BTNHD site dot local or www dot BTNHD site dot local.
And the next thing is I am going to add a parameter of index and point it to index dot
HTML, we can also index the following two files which would be index dot htm
once you make those modifications just save the file
and exit out, and it should bring you back into the terminal prompt and as always we
need to run a reload and just make sure you hit the reload hit ENTER again you're not
going to get a status, but if you want to know the status of the reload just make sure
you run the systemctl status nginx hit Enter, and it will show you right the logs that he
was reloading and reloaded with no problem.
And finally, what I did was test out my site but rather than opening up Firefox and typing
in localhost I just did a command of curl local host and bam.
There you go.
Awesome.
That is how we create a virtual host and that's it guys hopefully you guys enjoyed this video
make sure to hit that thumbs up.
Do not forget about punch, elbow and smashing that subscribe button to get the latest and
greatest from this guy, and I'll catch you guys on the next one.
Peace out.