In this new section of the Course we'll finally get rid of their default engineers holding page by creating
a basic virtual host to serve static files from a directory on our server.
To demonstrate this I've created a directory called sites slash demo at the root of my server and inside
sites slash demo I've uploaded a very simple single page website which you can find linked in the list
and resources should you want to use the same which will look like this.
Alternatively any other sample site.
Like the bootstrap boiler plate will work just fine.
The files I've uploaded consists of a single HDMI file indexed dot HD A C S S file which is linked to
in indexed updated email and a P N G image thumb dot P in G.
This way we have a good mix of content types whilst keeping it fairly simple.
The main configuration file we're going to edit is ATC slash in X slash engine X dot conf which at the
moment is still serving the default holding page.
I've got the engine file open in my editor and as it's going to be best to start from scratch here I'll
go ahead and delete everything inside the HTP context.
These bits at the top or in the main context as well and everything inside the event context.
Note that even though we won't be adding anything to the event context we do need to keep it for the
configuration to be considered valid.
Then first thing we're going to want to define a virtual host.
Each virtual host being a new server context or server block like so a virtual host or server context
is essentially responsible for listening on a port typically bought eighty four HDTV or 4 for 3 4 HDD
p s for a given IP address or domain.
So in our case starting with plane HDP port 80 we can say listen 80 and close with a semicolon which
is important.
Now you could leave out this listen directive.
In which case engineers will assume port 80 by default but it is considered good practice to include
it anyway.
Next we'll said the server name which is the domain sub domain or IP address for which the server context
exists.
In our case not having the domain name configured.
I'll simply use the IP address of this machine now.
Note that server names can also include wildcard characters asterisks which in the case of this example
will accept connections for any sub domain of this domain.
Not ever common use case but just something to be aware of.
Finally will define the root directive.
This being the root path from which engine X will be serving requests or interpreting static requests
from.
For example say the server receives a request for images slash cat dog PRNG by default engine X will
look for that file in the root path.
So whatever we said this root directive to slash images slash cette dot binjie Meaning we'll said this
to slash sites slash demo in order to serve static requests from that demo directory.
Save that and now for these changes to take effect will have to reload the and XT configuration using
our system D service.
We use the reload command over the restart command as this way we prevent any downtime.
If the configuration contains any errors the reload will simply fail but not stop engine X with the
current configuration.
Where's a restart will first stop engine X and then should the new configuration contain any errors.
Refuse to start back up.
Not what we want.
We could of course also manually verify this new configuration by running engine X with a T flag.
Like so syntax is okay.
This should be the first test whenever a new configuration isn't working as expected.
Chances are this a syntax error and the new configuration just didn't load reload.
All done.
Head over to the browser reload and we get this rather ugly htl page.
Not quite what we were expecting.
And if you noticed the problem here is that we don't have any styles applied from that linked style
Dotti SS file Now whilst at first it might seem like the style sheet isn't being loaded.
If we check in the browser development tools we see that everything is in fact loaded just fine.
So what's happening here is that engine X is sending the wrong MIME type with the style sheet.
We can confirm this by requesting the style Dotti assess headers using curl curl.
Capital H flag.
H T T P the server i b.
Slash style Dotti assess and there we have it content-type Text slash plane.
So to fix this we need to provide engine X with content types for given file extensions which we can
do using a new context called types like so.
Then we can specify a type let's say text slash h.t. amelle so a standard h.t. email MIME type to be
associated with files using the h.t. EMAIL extension or for that broken stylesheet text slash see assess
for files with a C S S extension and so on.
But there is an easier way.
Engine X allows us to include pieces of configuration from seperate files and one of those files that
already exist is the mime dot types file.
In ATC slash in Genex there.
Which if we check the contents.
Contains that very types context.
We just create it.
But with a much more complete selection of MIME types already defined including variations of file extensions
such as j peg and J.
P. G.
So instead of defining these ourselves we can include the contents of this file directly into our configuration
by saying include the relative path to that file which in this case being in the same directory as the
engine X dot com file is simply mime dot types.
Save this.
Reload the configuration.
We can confirm the MIME type by checking that stylesheets head again.
And this time we get the correct text slash C S S reload the browser and everything works as expected
with style dotsie assessed correctly interpret it as a style sheet.
That's all this to the most basic.
Engine X V housed and static file serving in the next lesson we'll see how to intercept specific requests
through the use of location blocks.