1 00:00:04,390 --> 00:00:09,790 In this new section of the Course we'll finally get rid of their default engineers holding page by creating 2 00:00:09,790 --> 00:00:15,440 a basic virtual host to serve static files from a directory on our server. 3 00:00:15,580 --> 00:00:23,140 To demonstrate this I've created a directory called sites slash demo at the root of my server and inside 4 00:00:23,140 --> 00:00:29,700 sites slash demo I've uploaded a very simple single page website which you can find linked in the list 5 00:00:29,720 --> 00:00:34,890 and resources should you want to use the same which will look like this. 6 00:00:34,900 --> 00:00:37,170 Alternatively any other sample site. 7 00:00:37,180 --> 00:00:40,650 Like the bootstrap boiler plate will work just fine. 8 00:00:40,690 --> 00:00:48,370 The files I've uploaded consists of a single HDMI file indexed dot HD A C S S file which is linked to 9 00:00:48,420 --> 00:00:54,130 in indexed updated email and a P N G image thumb dot P in G. 10 00:00:54,250 --> 00:00:58,930 This way we have a good mix of content types whilst keeping it fairly simple. 11 00:00:58,930 --> 00:01:06,220 The main configuration file we're going to edit is ATC slash in X slash engine X dot conf which at the 12 00:01:06,220 --> 00:01:09,690 moment is still serving the default holding page. 13 00:01:09,820 --> 00:01:15,610 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 14 00:01:15,610 --> 00:01:19,720 go ahead and delete everything inside the HTP context. 15 00:01:19,960 --> 00:01:26,520 These bits at the top or in the main context as well and everything inside the event context. 16 00:01:26,530 --> 00:01:31,540 Note that even though we won't be adding anything to the event context we do need to keep it for the 17 00:01:31,540 --> 00:01:33,690 configuration to be considered valid. 18 00:01:34,400 --> 00:01:38,440 Then first thing we're going to want to define a virtual host. 19 00:01:38,510 --> 00:01:46,550 Each virtual host being a new server context or server block like so a virtual host or server context 20 00:01:46,580 --> 00:01:54,350 is essentially responsible for listening on a port typically bought eighty four HDTV or 4 for 3 4 HDD 21 00:01:54,350 --> 00:01:58,850 p s for a given IP address or domain. 22 00:01:58,880 --> 00:02:07,340 So in our case starting with plane HDP port 80 we can say listen 80 and close with a semicolon which 23 00:02:07,340 --> 00:02:08,880 is important. 24 00:02:08,890 --> 00:02:11,100 Now you could leave out this listen directive. 25 00:02:11,120 --> 00:02:16,880 In which case engineers will assume port 80 by default but it is considered good practice to include 26 00:02:16,880 --> 00:02:18,200 it anyway. 27 00:02:18,230 --> 00:02:25,070 Next we'll said the server name which is the domain sub domain or IP address for which the server context 28 00:02:25,070 --> 00:02:26,100 exists. 29 00:02:26,210 --> 00:02:28,860 In our case not having the domain name configured. 30 00:02:28,910 --> 00:02:32,690 I'll simply use the IP address of this machine now. 31 00:02:32,720 --> 00:02:38,780 Note that server names can also include wildcard characters asterisks which in the case of this example 32 00:02:38,780 --> 00:02:42,980 will accept connections for any sub domain of this domain. 33 00:02:42,980 --> 00:02:46,500 Not ever common use case but just something to be aware of. 34 00:02:46,850 --> 00:02:49,640 Finally will define the root directive. 35 00:02:49,670 --> 00:02:56,030 This being the root path from which engine X will be serving requests or interpreting static requests 36 00:02:56,030 --> 00:02:57,020 from. 37 00:02:57,110 --> 00:03:04,490 For example say the server receives a request for images slash cat dog PRNG by default engine X will 38 00:03:04,490 --> 00:03:07,020 look for that file in the root path. 39 00:03:07,190 --> 00:03:15,260 So whatever we said this root directive to slash images slash cette dot binjie Meaning we'll said this 40 00:03:15,260 --> 00:03:22,180 to slash sites slash demo in order to serve static requests from that demo directory. 41 00:03:22,490 --> 00:03:29,240 Save that and now for these changes to take effect will have to reload the and XT configuration using 42 00:03:29,240 --> 00:03:31,250 our system D service. 43 00:03:31,340 --> 00:03:36,660 We use the reload command over the restart command as this way we prevent any downtime. 44 00:03:36,890 --> 00:03:42,440 If the configuration contains any errors the reload will simply fail but not stop engine X with the 45 00:03:42,440 --> 00:03:44,090 current configuration. 46 00:03:44,120 --> 00:03:50,430 Where's a restart will first stop engine X and then should the new configuration contain any errors. 47 00:03:50,480 --> 00:03:52,090 Refuse to start back up. 48 00:03:52,130 --> 00:03:53,630 Not what we want. 49 00:03:53,630 --> 00:03:59,410 We could of course also manually verify this new configuration by running engine X with a T flag. 50 00:03:59,450 --> 00:04:02,410 Like so syntax is okay. 51 00:04:02,750 --> 00:04:07,340 This should be the first test whenever a new configuration isn't working as expected. 52 00:04:07,340 --> 00:04:12,900 Chances are this a syntax error and the new configuration just didn't load reload. 53 00:04:14,680 --> 00:04:15,820 All done. 54 00:04:15,820 --> 00:04:22,360 Head over to the browser reload and we get this rather ugly htl page. 55 00:04:22,600 --> 00:04:24,710 Not quite what we were expecting. 56 00:04:24,760 --> 00:04:29,820 And if you noticed the problem here is that we don't have any styles applied from that linked style 57 00:04:29,820 --> 00:04:35,320 Dotti SS file Now whilst at first it might seem like the style sheet isn't being loaded. 58 00:04:35,320 --> 00:04:40,990 If we check in the browser development tools we see that everything is in fact loaded just fine. 59 00:04:41,140 --> 00:04:46,700 So what's happening here is that engine X is sending the wrong MIME type with the style sheet. 60 00:04:46,780 --> 00:04:52,230 We can confirm this by requesting the style Dotti assess headers using curl curl. 61 00:04:52,390 --> 00:04:53,950 Capital H flag. 62 00:04:54,250 --> 00:04:56,770 H T T P the server i b. 63 00:04:56,890 --> 00:05:03,690 Slash style Dotti assess and there we have it content-type Text slash plane. 64 00:05:03,820 --> 00:05:10,270 So to fix this we need to provide engine X with content types for given file extensions which we can 65 00:05:10,270 --> 00:05:13,880 do using a new context called types like so. 66 00:05:14,610 --> 00:05:21,780 Then we can specify a type let's say text slash h.t. amelle so a standard h.t. email MIME type to be 67 00:05:21,780 --> 00:05:30,420 associated with files using the h.t. EMAIL extension or for that broken stylesheet text slash see assess 68 00:05:30,780 --> 00:05:34,710 for files with a C S S extension and so on. 69 00:05:34,980 --> 00:05:37,330 But there is an easier way. 70 00:05:37,350 --> 00:05:44,130 Engine X allows us to include pieces of configuration from seperate files and one of those files that 71 00:05:44,130 --> 00:05:47,170 already exist is the mime dot types file. 72 00:05:47,190 --> 00:05:50,320 In ATC slash in Genex there. 73 00:05:51,750 --> 00:05:54,120 Which if we check the contents. 74 00:05:56,090 --> 00:05:58,060 Contains that very types context. 75 00:05:58,070 --> 00:05:59,300 We just create it. 76 00:05:59,480 --> 00:06:05,900 But with a much more complete selection of MIME types already defined including variations of file extensions 77 00:06:05,960 --> 00:06:07,640 such as j peg and J. 78 00:06:07,640 --> 00:06:08,510 P. G. 79 00:06:09,510 --> 00:06:16,260 So instead of defining these ourselves we can include the contents of this file directly into our configuration 80 00:06:16,290 --> 00:06:23,080 by saying include the relative path to that file which in this case being in the same directory as the 81 00:06:23,080 --> 00:06:27,540 engine X dot com file is simply mime dot types. 82 00:06:28,050 --> 00:06:29,370 Save this. 83 00:06:30,550 --> 00:06:33,100 Reload the configuration. 84 00:06:33,100 --> 00:06:37,240 We can confirm the MIME type by checking that stylesheets head again. 85 00:06:38,290 --> 00:06:45,880 And this time we get the correct text slash C S S reload the browser and everything works as expected 86 00:06:46,150 --> 00:06:50,220 with style dotsie assessed correctly interpret it as a style sheet. 87 00:06:50,500 --> 00:06:52,120 That's all this to the most basic. 88 00:06:52,120 --> 00:06:58,330 Engine X V housed and static file serving in the next lesson we'll see how to intercept specific requests 89 00:06:58,360 --> 00:07:00,670 through the use of location blocks.