📺 Develpreneur YouTube Episode

Video + transcript

Creating Virtual Hosts on Apache2 - Tutorial

2023-10-05 •Youtube

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
0.199

well hello welcome back we are

2.36

continuing talking about our URL

4.64

shortener application and today we're

7

going to talk a little bit about some of

8.44

the deployment kind of things we are

10.519

specifically going to look at creating a

13.36

virtual host in Apache 2 now if you

16.4

haven't followed before this and all you

17.92

need to do is create a virtual host in

19.68

Apache 2 you're going to be able to see

21.72

this and should be able to just dive

24.4

right into it it's actually fairly

27.96

straightforward so what we're going to

29.64

do

30.64

is over in our Apache world and let's do

34.079

this if you look at and this is on a dbn

38.84

uh server you may be on something a

40.719

little different it's going to look a

42.039

it'll be vary a little bit but

44.079

effectively what you're going to do is

45.719

you're going to find for your Apache

48.199

where are the config files some of the

51

easiest ways probably just go look for

52.44

Apache 2. Co NF and you should see the

57.719

ones that are conf available enable

59.879

abled and then also sites available and

61.96

sites

62.8

enabled so what you want to do is you

64.879

want to go into sites

68.159

enabled and you're are going

70.88

to create a little CF file now let me

74.92

get this over here which probably a

76.36

little easier to understand because I

78.08

want to walk through this now by

80.68

default now this uh one thing this is

83.24

going to assume that you have a port 80

85.64

which is your standard connection HTTP

88.52

and Port 44 three which is going to be

90.72

your typical

92.439

https and there are ways that we can

95.479

really work with this stuff but for now

97.88

we're going to keep it fairly

99.64

straightforward because what we want to

101.32

do here is we're going to say hey for

103.799

our server which has an IP address which

107.68

is I think this thing somewhere I got to

111.719

go find it somewhere out here go I'll go

115.6

see uh let's see let's do this real

118.84

quick

120.6

uh so it is so I have this server out

128.2

there and let me go back to here I want

131.8

to show that real

134.239

quick so if I go out to my

137.4

server and I go to

140.76

http that email or sorry that IP address

144.239

then I'm going to get this thing that's

146.72

at the root and that's not what I want

150.319

what I actually want is when I go to

152.04

this server I want to go to see this

155.4

page and the way we're going to do that

158.319

is we're going to do a redirect we're

159.68

going to say if you come into the site

162.2

into the server with the server name DPL

165.72

nk. us which is what I want to you know

168.68

this is my domain

170.319

name then or www. DPL link. us if either

175.48

of those come in then I'm not going to

177.72

run the normal one I'm going to run the

179.36

one that comes off of WW off of this

182.319

folder so that folder is going to exist

184.44

here if I go look at that VAR www

189.2

shorty you're going to see that there

191.159

are some files here this is that's where

194.04

I'm going to L otherwise by default it's

196.959

going to go to far www

199.84

HTML which is just a simple H you know

202.4

index page and if I do

204.4

that this I think it is I may have a

206.599

default setup it's a little different uh

208.76

HTML

212.599

uh no okay I actually have a default

214.28

already set up this so this is a little

215.68

more complicated but that's neither here

218.04

nor there so what we're going to do is

221.64

we're going to say this is where our

222.92

site is so if I put like an

225.2

index.html here VAR www shorty

228.4

index.html that is where I'm going to

231

get redirected if I come into my server

234.04

here you know using this name on this

237.239

port so if I go http I'm going to go

240.2

here if I also and we're going to see

242.599

down here I'm basically copying this

244.239

stuff because

245.599

https also if it's DP link. us it's

249.76

going to go to this folder so whichever

251.76

what want to do I'm going to go ahead

254.519

and send them here now I do have a

257.4

little bonus here is that

263.28

um uh

265.08

well it is a separate one to set up the

268.72

uh certificates for https so I'm really

270.96

just setting you up for the uh the

273.08

redirect right now we there'll be

274.96

another time we can talk about we'll

277.32

have another one where we're talking

278.199

about actually setting up the keys and

280.24

actually using uh the chat the uh

283.28

certbot and let's encrypt and getting

285.16

that stuff set up that's slightly

286.479

different one so this won't if you do

288.88

this straight up and have not done

290.88

anything else with your server you're

292.36

going to run into some issues here uh

294.96

but you can find default uh PM files so

299.039

you can set it up by default uh but it's

302.44

probably easier to just search our stuff

303.8

and find setting up https on Apache 2

308

and you'll be able to set that up now

309.919

what we've got here as well got some

311.759

additional stuff so we're saying hey

312.96

we're going to put into DPR error.log

315.84

this is where we're going to log stuff

317.36

to this specific domain so if I go look

320.24

at the Apache loger which happens to

324.16

be uh I think it's VAR

327.52

log and can I get in here here nope I

330.52

have to

332.68

pseudo it's one of those funny things

334.56

about Apache it likes to be root level

336.8

so if I go oops if I go

338.8

here I can see where I've got so this is

341.68

my standard error log but I also have

344.199

one specifically for this site so if I

347.52

come in to DPL link. us this is where my

351.36

log's going to go now my access log it's

353.72

just going to use the normal access log

356.56

but for errors and this is my custom log

358.759

and so here's my a logs it's just going

360.479

to go to this different one rewrite is

363.4

basically just saying hey if I've got to

367.16

if I've got either of these names that

370.599

come in then I'm going to change it so

373.68

it's going to be uh DP link or uh DP

377.599

it's actually it's going to use I'm

378.479

sorry it's going to use this name so

381

regardless it's going to use this if I

382.4

wanted my server to name just be

384.08

something like uh my server

388.12

dot then then it would actually rewrite

391.199

and I would see my server. DPL link. us

395.28

up here instead of DPL link.

398.199

us and then all I need to do once I have

400.479

built that out I'm going put that in my

403.8

let see where did I change that okay so

405.68

I just change that and I am going to

407.96

place those and they should be wherever

411.12

my config files lived and for Apache 2

414.479

you're going to have two folders so

415.72

you're going to have sites available so

419.039

if I do sites available I'm going to see

422.639

that I have my shorty config there I'm

425.759

also going to have it in sites

429.44

enabled and I'm going to see it there

431.84

and all I have to do at that point is do

433.44

a restart of

436.68

my Apache which I believe I forget which

439.759

one uh it's going to be I don't have it

442.96

let's see

446.319

oh I think I'm still root I am let me

449.599

switch back here

453.56

whoops you have to run it as a route I

456.319

think uh oh I don't have it

459.4

there

461.879

um it may be too far back in my

465.319

history yep okay it's too far back in my

467.72

history

468.879

apologies

470.479

um

473.08

actually uh let me go look real quick

475.599

because I don't want to do it so that's

476.84

admin

478.319

okay

481.72

uh who am I there we go and now if I do

485.36

history grap Apache that's probably who

487.96

I

488.68

am there it is um there we go so I'm

492.72

going to do a

494.479

pseudo and uh you check that another

497.159

time if you don't know what pseudo is

498.319

it's basically just saying hey as root

500

because I need to run as a root user uh

502.199

to be able to restart

503.919

systems system level things and this

506.919

will be a little different again

507.96

depending on what your operating system

509.28

system is um but then all you're going

511.479

to do is you're going to use in this

512.88

case uh we use a system control restart

516.44

and then apache2 so if I do that it's

518.959

going to restart my server and then boom

521.719

I'm going to be able to come in here if

523.919

I go to this if I come in here

528.959

uh add then it's going to be able to

532.72

send me to this page as opposed to if I

536.24

did just

538.2

the

540.32

IP address it gives me a whole different

542.2

location and I don't remember if this is

545.32

I don't know if

548.279

that's and yeah so that HTTP does not

551.04

redirect oh so you can also look so if I

553.04

go HTTP col back SL

555.92

DP link.

558.519

us you're going to see it's not secure

561.76

it's not going to force it but if I come

566.079

https I'm still going to get to the site

568.64

but I'm going here so I'm not actually

570.12

forcing it that's another thing you

571.56

could do is you can actually do oops you

573.72

can do a

576.399

redirect and you can actually do a

578.279

rewrite and rewrite it as an https so I

582.04

could come in here and force everything

583.76

to go https I do not want to do that and

587.12

we'll talk about that when we talk about

588.64

the API because I'm not going to I'm not

591.24

doing an SSL on our little API because

593.72

it's something I feel like we don't

595.56

really need to secure we're not sending

597

passwords across or anything so so we're

599.76

going to leave it like this and that's

602.04

going to allow us in our uh mappings

606.12

that when we come in we'll be able to do

607.8

an

609.36

HTTP with the port for the API because

613.64

we've opened that up we're going to

614.68

specifically go and we'll be able to see

616.2

our API and that will be a slightly

618.92

different one but this one I wanted to

620.079

cover right here is it's very simple to

621.68

do virtual host you can do this for as

625.079

many sites as you want uh if you want to

626.92

see This Server the exact same thing I

629.36

think you may have noticed I have a

632.2

scrum for everyone out there so if you

634.079

go scrum for everyone it goes to this

635.92

one which looks very familiar that's

637.56

page we just hit a little bit

639.519

ago and that is um also it's a on the

644.72

same site and you can see oops if I go

647.88

back over to the site

651.2

here then if you want to go back and see

654.519

uh let's see ety Apache

658.04

2

659.6

sites

661.079

enabled if we look at the scrum for

663.519

everyone we will see that this

666.24

one um if you come in as scrum for

668.72

everyone.com it's going to redirect to a

671.32

different

672.32

folder and we can actually even see here

675.24

we can see where we have a rewrite rule

677.72

where we said hey whatever they come in

679.32

as we're going to rewrite it to https

681.68

CHR backback SL blah blah blah serame

684.24

all that good stuff and so it's going to

685.8

force them over here to the http yes so

690.12

that is creating virtual hosts in Apache

692.6

2 again very

694.36

straightforward it may seem complex and

697.88

sometimes it's a little intimidating the

699

first time around but once you get going

700.959

it's really easy and uh the next thing

702.839

we'll talk about or one of the things

704.04

we'll talk about is also creating that

706.519

SSL certificate a way to do it free so

708.839

you don't have to spend you 100 150

711.6

whatever it is bucks a year or more to

714.16

get an SL SSL certificate it is a very

717

good uh using certbot excellent way to

719.56

use a certificate fired up your off and

722.279

running and you don't have to pay money

723.68

which is always a bonus uh as always if

726.8

you have any questions shoot us an email

728.68

at info@ develop

730.399

or.com and uh we'll we'll do our best to

733.199

to help you walk through it if you have

734.519

any request for future shows as well

736.92

send something the same place or there's

739.44

a contact form on the developer or

741.76

website you can sign up there and get

744

some information from us always happy to

746.519

reach out or other thing leave comment

748.88

comments down in the show notes and

750.519

we'll do our rest to get those turned

751.839

around as fast as possible to help you

753.959

if you run into any snags thanks a lot

756.44

and have yourself a great day hello this

758.92

is Rob with develop or also known as

761.079

building better developers wanted to

763.48

announce that we have school.

764.959

developer.com feel free to check it out

767.88

if you like any of this information any

770.519

of the content that we've sent and you

771.88

would like to see more you can come out

773.76

you can enroll for free we have free

775.76

courses we've got places for you to get

778.519

better at just learning a technology or

780.959

how toos you can work on your business

782.959

skills we can help you with becoming a

785.519

better developer as encoding and things

787.959

like that a lot of the stuff you've seen

789.6

on YouTube we also have out at school.

792.48

develop andur we have it a little more

794.519

of a uh educational format and a way for

797.079

you to track your progress as you move

799.6

forward becoming a better developer