Although we have HTTPS up and running,
we still have a problem that users can still legitimately access the HTTP site,
and depending on their browser,
they might not even get any warning that their data
is not going to be protected.
We can overcome this by editing our default site.
So this was a site that's always been up and running, 000‑default.conf.
It's already enabled, so we don't need to worry about enabling it,
but in the configuration file,
if we go through and take a look for our VirtualHost opening block,
and we can change then the contents.
It won't have a ServerName, so the ServerName will be empty,
and this has been causing us a problem throughout the
course because it's never been set up.
We set it up for the port 443 VirtualHost, but not the port 80 VirtualHost.
So here we can go through and correct that.
But more importantly, the redirect line is redirecting everything,
so we're just using the /,
so we say anything on our port 80 server is being
redirected through to HTTPS and Ubuntu.
So in this way we can make sure that we are able to access the data securely,
even if we happen to use an HTTP request through to port 80.
Once we've done that, we can then go through and restart our website.
Now this is all that we need to do, so it's relatively short and straightforward,
so why don't we dive out to our command line now where we go through and
modify our configuration to allow HTTP requests to be accepted,
but redirected through to the secure HTTPS.
So editing our default site, adding the ServerName and Redirect directives,
and then we should be good to go.
Come on, let's find that command line.
And look at this,
I'm really happy to be back at the command line because this
is where our learning is going to happen.
Now if we go through and run the apachectl configtest,
we can always go through and check our configuration.
And we can see we're getting a warning here.
It's not so much an error, but a warning that we could not then resolve our name.
Now we could then set our ServerName.
We set this for our port 443, our HTTPS site,
but we haven't as yet set it for our default port 80 site.
So this is something that we can do.
But we also, as we said,
we want to protect against people accessing the port 80 site perhaps without
realizing and not knowing their data isn't going to be secured.
So that site was already enabled,
and we can then go through and visit the site by editing the sites available.
Remember, that's the raw data rather than the linked data,
although it wouldn't really make any difference which one we access.
But as I go through then to 000‑default.conf,
we can move it to the top of the screen just so you
can see it a little bit more easily.
Now we have a lot of information in here.
If we're going to be redirecting, though,
often it doesn't really matter so much about this information.
So I'm clearing pretty much everything out.
I can delete 10 lines, another 10 lines,
maybe 5 lines here, and even without counting,
you can see how quickly it is that I could start
clearing all of that information out.
Now it looks very drastic, and I don't doubt that it looks very bad.
However,
we saw from the slides the reality is I only need a
couple of configuration lines here.
So this is my VirtualHost for port 80, my HTTP site,
and I can add in the ServerName directive.
So again, this is going to be Ubuntu.
And we can then go through and specify our redirect,
and this is where we can go and put just /.
This is then saying our root directory.
Everything on this VirtualHost is going to be redirected.
And where is it going to be redirected to?
Well, HTTPS, and then, of course, Ubuntu.
And we can go through and put the root directory then on our Ubuntu server,
which is, of course, not the file system root,
but the root of our web server.
So we can see then that we've changed all of that
information into two effective lines because we don't need
to host any information for this site.
We just need to make sure the system is restarted and then all
of our requests to port 80 are going to be redirected through
to port 443 and being secured.
I can show you this happening,
especially if we go through and use our command‑line browser,
and explicitly say we want to go to the HTTP site,
so Ubuntu.
We can see now that we've been told to accept the self‑signed certificate.
We can here enter in our warning that we're accessing
then an unverified certificate,
but we can also see towards the bottom of the screen now
that we are viewing this over SSL,
so we've been able to secure even our HTTP connections through to HTTPS,
which was what our desired effect was. Be proud of yourself!