Detailed Notes
This video looks at one piece of our URL shortener solution. Our site uses Apache 2 as the web server and we want to create virtual hosts so we can direct traffic based on a domain name as opposed to just a server IP address.
You can find out more through our online classes at https://school.develpreneur.com and register for free. Registration will add you to our email list and you will periodically receive coupons for courses as well as notifications of the latest releases.
Transcript Text
well hello welcome back we are continuing talking about our URL shortener application and today we're going to talk a little bit about some of the deployment kind of things we are specifically going to look at creating a virtual host in Apache 2 now if you haven't followed before this and all you need to do is create a virtual host in Apache 2 you're going to be able to see this and should be able to just dive right into it it's actually fairly straightforward so what we're going to do is over in our Apache world and let's do this if you look at and this is on a dbn uh server you may be on something a little different it's going to look a it'll be vary a little bit but effectively what you're going to do is you're going to find for your Apache where are the config files some of the easiest ways probably just go look for Apache 2. Co NF and you should see the ones that are conf available enable abled and then also sites available and sites enabled so what you want to do is you want to go into sites enabled and you're are going to create a little CF file now let me get this over here which probably a little easier to understand because I want to walk through this now by default now this uh one thing this is going to assume that you have a port 80 which is your standard connection HTTP and Port 44 three which is going to be your typical https and there are ways that we can really work with this stuff but for now we're going to keep it fairly straightforward because what we want to do here is we're going to say hey for our server which has an IP address which is I think this thing somewhere I got to go find it somewhere out here go I'll go see uh let's see let's do this real quick uh so it is so I have this server out there and let me go back to here I want to show that real quick so if I go out to my server and I go to http that email or sorry that IP address then I'm going to get this thing that's at the root and that's not what I want what I actually want is when I go to this server I want to go to see this page and the way we're going to do that is we're going to do a redirect we're going to say if you come into the site into the server with the server name DPL nk. us which is what I want to you know this is my domain name then or www. DPL link. us if either of those come in then I'm not going to run the normal one I'm going to run the one that comes off of WW off of this folder so that folder is going to exist here if I go look at that VAR www shorty you're going to see that there are some files here this is that's where I'm going to L otherwise by default it's going to go to far www HTML which is just a simple H you know index page and if I do that this I think it is I may have a default setup it's a little different uh HTML uh no okay I actually have a default already set up this so this is a little more complicated but that's neither here nor there so what we're going to do is we're going to say this is where our site is so if I put like an index.html here VAR www shorty index.html that is where I'm going to get redirected if I come into my server here you know using this name on this port so if I go http I'm going to go here if I also and we're going to see down here I'm basically copying this stuff because https also if it's DP link. us it's going to go to this folder so whichever what want to do I'm going to go ahead and send them here now I do have a little bonus here is that um uh well it is a separate one to set up the uh certificates for https so I'm really just setting you up for the uh the redirect right now we there'll be another time we can talk about we'll have another one where we're talking about actually setting up the keys and actually using uh the chat the uh certbot and let's encrypt and getting that stuff set up that's slightly different one so this won't if you do this straight up and have not done anything else with your server you're going to run into some issues here uh but you can find default uh PM files so you can set it up by default uh but it's probably easier to just search our stuff and find setting up https on Apache 2 and you'll be able to set that up now what we've got here as well got some additional stuff so we're saying hey we're going to put into DPR error.log this is where we're going to log stuff to this specific domain so if I go look at the Apache loger which happens to be uh I think it's VAR log and can I get in here here nope I have to pseudo it's one of those funny things about Apache it likes to be root level so if I go oops if I go here I can see where I've got so this is my standard error log but I also have one specifically for this site so if I come in to DPL link. us this is where my log's going to go now my access log it's just going to use the normal access log but for errors and this is my custom log and so here's my a logs it's just going to go to this different one rewrite is basically just saying hey if I've got to if I've got either of these names that come in then I'm going to change it so it's going to be uh DP link or uh DP it's actually it's going to use I'm sorry it's going to use this name so regardless it's going to use this if I wanted my server to name just be something like uh my server dot then then it would actually rewrite and I would see my server. DPL link. us up here instead of DPL link. us and then all I need to do once I have built that out I'm going put that in my let see where did I change that okay so I just change that and I am going to place those and they should be wherever my config files lived and for Apache 2 you're going to have two folders so you're going to have sites available so if I do sites available I'm going to see that I have my shorty config there I'm also going to have it in sites enabled and I'm going to see it there and all I have to do at that point is do a restart of my Apache which I believe I forget which one uh it's going to be I don't have it let's see oh I think I'm still root I am let me switch back here whoops you have to run it as a route I think uh oh I don't have it there um it may be too far back in my history yep okay it's too far back in my history apologies um actually uh let me go look real quick because I don't want to do it so that's admin okay uh who am I there we go and now if I do history grap Apache that's probably who I am there it is um there we go so I'm going to do a pseudo and uh you check that another time if you don't know what pseudo is it's basically just saying hey as root because I need to run as a root user uh to be able to restart systems system level things and this will be a little different again depending on what your operating system system is um but then all you're going to do is you're going to use in this case uh we use a system control restart and then apache2 so if I do that it's going to restart my server and then boom I'm going to be able to come in here if I go to this if I come in here uh add then it's going to be able to send me to this page as opposed to if I did just the IP address it gives me a whole different location and I don't remember if this is I don't know if that's and yeah so that HTTP does not redirect oh so you can also look so if I go HTTP col back SL DP link. us you're going to see it's not secure it's not going to force it but if I come https I'm still going to get to the site but I'm going here so I'm not actually forcing it that's another thing you could do is you can actually do oops you can do a redirect and you can actually do a rewrite and rewrite it as an https so I could come in here and force everything to go https I do not want to do that and we'll talk about that when we talk about the API because I'm not going to I'm not doing an SSL on our little API because it's something I feel like we don't really need to secure we're not sending passwords across or anything so so we're going to leave it like this and that's going to allow us in our uh mappings that when we come in we'll be able to do an HTTP with the port for the API because we've opened that up we're going to specifically go and we'll be able to see our API and that will be a slightly different one but this one I wanted to cover right here is it's very simple to do virtual host you can do this for as many sites as you want uh if you want to see This Server the exact same thing I think you may have noticed I have a scrum for everyone out there so if you go scrum for everyone it goes to this one which looks very familiar that's page we just hit a little bit ago and that is um also it's a on the same site and you can see oops if I go back over to the site here then if you want to go back and see uh let's see ety Apache 2 sites enabled if we look at the scrum for everyone we will see that this one um if you come in as scrum for everyone.com it's going to redirect to a different folder and we can actually even see here we can see where we have a rewrite rule where we said hey whatever they come in as we're going to rewrite it to https CHR backback SL blah blah blah serame all that good stuff and so it's going to force them over here to the http yes so that is creating virtual hosts in Apache 2 again very straightforward it may seem complex and sometimes it's a little intimidating the first time around but once you get going it's really easy and uh the next thing we'll talk about or one of the things we'll talk about is also creating that SSL certificate a way to do it free so you don't have to spend you 100 150 whatever it is bucks a year or more to get an SL SSL certificate it is a very good uh using certbot excellent way to use a certificate fired up your off and running and you don't have to pay money which is always a bonus uh as always if you have any questions shoot us an email at info@ develop or.com and uh we'll we'll do our best to to help you walk through it if you have any request for future shows as well send something the same place or there's a contact form on the developer or website you can sign up there and get some information from us always happy to reach out or other thing leave comment comments down in the show notes and we'll do our rest to get those turned around as fast as possible to help you if you run into any snags thanks a lot and have yourself a great day hello this is Rob with develop or also known as building better developers wanted to announce that we have school. developer.com feel free to check it out if you like any of this information any of the content that we've sent and you would like to see more you can come out you can enroll for free we have free courses we've got places for you to get better at just learning a technology or how toos you can work on your business skills we can help you with becoming a better developer as encoding and things like that a lot of the stuff you've seen on YouTube we also have out at school. develop andur we have it a little more of a uh educational format and a way for you to track your progress as you move forward becoming a better developer
Transcript Segments
well hello welcome back we are
continuing talking about our URL
shortener application and today we're
going to talk a little bit about some of
the deployment kind of things we are
specifically going to look at creating a
virtual host in Apache 2 now if you
haven't followed before this and all you
need to do is create a virtual host in
Apache 2 you're going to be able to see
this and should be able to just dive
right into it it's actually fairly
straightforward so what we're going to
do
is over in our Apache world and let's do
this if you look at and this is on a dbn
uh server you may be on something a
little different it's going to look a
it'll be vary a little bit but
effectively what you're going to do is
you're going to find for your Apache
where are the config files some of the
easiest ways probably just go look for
Apache 2. Co NF and you should see the
ones that are conf available enable
abled and then also sites available and
sites
enabled so what you want to do is you
want to go into sites
enabled and you're are going
to create a little CF file now let me
get this over here which probably a
little easier to understand because I
want to walk through this now by
default now this uh one thing this is
going to assume that you have a port 80
which is your standard connection HTTP
and Port 44 three which is going to be
your typical
https and there are ways that we can
really work with this stuff but for now
we're going to keep it fairly
straightforward because what we want to
do here is we're going to say hey for
our server which has an IP address which
is I think this thing somewhere I got to
go find it somewhere out here go I'll go
see uh let's see let's do this real
quick
uh so it is so I have this server out
there and let me go back to here I want
to show that real
quick so if I go out to my
server and I go to
http that email or sorry that IP address
then I'm going to get this thing that's
at the root and that's not what I want
what I actually want is when I go to
this server I want to go to see this
page and the way we're going to do that
is we're going to do a redirect we're
going to say if you come into the site
into the server with the server name DPL
nk. us which is what I want to you know
this is my domain
name then or www. DPL link. us if either
of those come in then I'm not going to
run the normal one I'm going to run the
one that comes off of WW off of this
folder so that folder is going to exist
here if I go look at that VAR www
shorty you're going to see that there
are some files here this is that's where
I'm going to L otherwise by default it's
going to go to far www
HTML which is just a simple H you know
index page and if I do
that this I think it is I may have a
default setup it's a little different uh
HTML
uh no okay I actually have a default
already set up this so this is a little
more complicated but that's neither here
nor there so what we're going to do is
we're going to say this is where our
site is so if I put like an
index.html here VAR www shorty
index.html that is where I'm going to
get redirected if I come into my server
here you know using this name on this
port so if I go http I'm going to go
here if I also and we're going to see
down here I'm basically copying this
stuff because
https also if it's DP link. us it's
going to go to this folder so whichever
what want to do I'm going to go ahead
and send them here now I do have a
little bonus here is that
um uh
well it is a separate one to set up the
uh certificates for https so I'm really
just setting you up for the uh the
redirect right now we there'll be
another time we can talk about we'll
have another one where we're talking
about actually setting up the keys and
actually using uh the chat the uh
certbot and let's encrypt and getting
that stuff set up that's slightly
different one so this won't if you do
this straight up and have not done
anything else with your server you're
going to run into some issues here uh
but you can find default uh PM files so
you can set it up by default uh but it's
probably easier to just search our stuff
and find setting up https on Apache 2
and you'll be able to set that up now
what we've got here as well got some
additional stuff so we're saying hey
we're going to put into DPR error.log
this is where we're going to log stuff
to this specific domain so if I go look
at the Apache loger which happens to
be uh I think it's VAR
log and can I get in here here nope I
have to
pseudo it's one of those funny things
about Apache it likes to be root level
so if I go oops if I go
here I can see where I've got so this is
my standard error log but I also have
one specifically for this site so if I
come in to DPL link. us this is where my
log's going to go now my access log it's
just going to use the normal access log
but for errors and this is my custom log
and so here's my a logs it's just going
to go to this different one rewrite is
basically just saying hey if I've got to
if I've got either of these names that
come in then I'm going to change it so
it's going to be uh DP link or uh DP
it's actually it's going to use I'm
sorry it's going to use this name so
regardless it's going to use this if I
wanted my server to name just be
something like uh my server
dot then then it would actually rewrite
and I would see my server. DPL link. us
up here instead of DPL link.
us and then all I need to do once I have
built that out I'm going put that in my
let see where did I change that okay so
I just change that and I am going to
place those and they should be wherever
my config files lived and for Apache 2
you're going to have two folders so
you're going to have sites available so
if I do sites available I'm going to see
that I have my shorty config there I'm
also going to have it in sites
enabled and I'm going to see it there
and all I have to do at that point is do
a restart of
my Apache which I believe I forget which
one uh it's going to be I don't have it
let's see
oh I think I'm still root I am let me
switch back here
whoops you have to run it as a route I
think uh oh I don't have it
there
um it may be too far back in my
history yep okay it's too far back in my
history
apologies
um
actually uh let me go look real quick
because I don't want to do it so that's
admin
okay
uh who am I there we go and now if I do
history grap Apache that's probably who
I
am there it is um there we go so I'm
going to do a
pseudo and uh you check that another
time if you don't know what pseudo is
it's basically just saying hey as root
because I need to run as a root user uh
to be able to restart
systems system level things and this
will be a little different again
depending on what your operating system
system is um but then all you're going
to do is you're going to use in this
case uh we use a system control restart
and then apache2 so if I do that it's
going to restart my server and then boom
I'm going to be able to come in here if
I go to this if I come in here
uh add then it's going to be able to
send me to this page as opposed to if I
did just
the
IP address it gives me a whole different
location and I don't remember if this is
I don't know if
that's and yeah so that HTTP does not
redirect oh so you can also look so if I
go HTTP col back SL
DP link.
us you're going to see it's not secure
it's not going to force it but if I come
https I'm still going to get to the site
but I'm going here so I'm not actually
forcing it that's another thing you
could do is you can actually do oops you
can do a
redirect and you can actually do a
rewrite and rewrite it as an https so I
could come in here and force everything
to go https I do not want to do that and
we'll talk about that when we talk about
the API because I'm not going to I'm not
doing an SSL on our little API because
it's something I feel like we don't
really need to secure we're not sending
passwords across or anything so so we're
going to leave it like this and that's
going to allow us in our uh mappings
that when we come in we'll be able to do
an
HTTP with the port for the API because
we've opened that up we're going to
specifically go and we'll be able to see
our API and that will be a slightly
different one but this one I wanted to
cover right here is it's very simple to
do virtual host you can do this for as
many sites as you want uh if you want to
see This Server the exact same thing I
think you may have noticed I have a
scrum for everyone out there so if you
go scrum for everyone it goes to this
one which looks very familiar that's
page we just hit a little bit
ago and that is um also it's a on the
same site and you can see oops if I go
back over to the site
here then if you want to go back and see
uh let's see ety Apache
2
sites
enabled if we look at the scrum for
everyone we will see that this
one um if you come in as scrum for
everyone.com it's going to redirect to a
different
folder and we can actually even see here
we can see where we have a rewrite rule
where we said hey whatever they come in
as we're going to rewrite it to https
CHR backback SL blah blah blah serame
all that good stuff and so it's going to
force them over here to the http yes so
that is creating virtual hosts in Apache
2 again very
straightforward it may seem complex and
sometimes it's a little intimidating the
first time around but once you get going
it's really easy and uh the next thing
we'll talk about or one of the things
we'll talk about is also creating that
SSL certificate a way to do it free so
you don't have to spend you 100 150
whatever it is bucks a year or more to
get an SL SSL certificate it is a very
good uh using certbot excellent way to
use a certificate fired up your off and
running and you don't have to pay money
which is always a bonus uh as always if
you have any questions shoot us an email
at info@ develop
or.com and uh we'll we'll do our best to
to help you walk through it if you have
any request for future shows as well
send something the same place or there's
a contact form on the developer or
website you can sign up there and get
some information from us always happy to
reach out or other thing leave comment
comments down in the show notes and
we'll do our rest to get those turned
around as fast as possible to help you
if you run into any snags thanks a lot
and have yourself a great day hello this
is Rob with develop or also known as
building better developers wanted to
announce that we have school.
developer.com feel free to check it out
if you like any of this information any
of the content that we've sent and you
would like to see more you can come out
you can enroll for free we have free
courses we've got places for you to get
better at just learning a technology or
how toos you can work on your business
skills we can help you with becoming a
better developer as encoding and things
like that a lot of the stuff you've seen
on YouTube we also have out at school.
develop andur we have it a little more
of a uh educational format and a way for
you to track your progress as you move
forward becoming a better developer