WEBVTT

00:02.950 --> 00:09.160
Let's discuss how we can make the configuration for our demo site more robust by adding location directives.

00:09.520 --> 00:15.820
Location directives allow us to extend our configuration based on URI or a uniform resource indicator

00:15.820 --> 00:18.670
that makes up the request being processed by the server.

00:19.030 --> 00:25.540
When we define a location, we use the location keyword, an optional modifier and a required location

00:25.540 --> 00:26.410
definition.

00:26.710 --> 00:31.450
Location directives are formatted as blocks and are defined inside server blocks.

00:31.780 --> 00:35.110
They can also be nested inside other location blocks.

00:35.500 --> 00:38.830
Inside the location block, we can include other directives.

00:39.190 --> 00:44.740
Specifically, we can include just about any directive that can be defined inside a server block.

00:45.070 --> 00:50.680
This makes locations very useful since we can configure Engine X to process different requests in ways

00:50.680 --> 00:54.370
similar to server blocks without having to create additional servers.

00:54.700 --> 01:01.000
When Engine X processes locations, it uses a series of matches to determine the best one to use.

01:01.360 --> 01:07.810
First, considering exact matches, then locations with prefixes and then locations with regular expressions.

01:08.200 --> 01:13.690
For more information on locations, take a look at the documentation on engine x dot org.

01:13.990 --> 01:19.270
Let's continue by going back to our development server as the root user and editing the configuration

01:19.270 --> 01:20.650
for our demo site.

01:21.010 --> 01:25.640
Let's add a new location block for an empty request or just the slash character.

01:25.660 --> 01:29.050
This will correspond to the root directory of our site.

01:29.410 --> 01:32.920
Inside this block, we'll add another directive Tree files.

01:33.250 --> 01:39.670
The Tree Files directive gives engine X a list of files or directories to look for relative to the location,

01:39.970 --> 01:43.450
The first file or directory that matches gets processed.

01:43.840 --> 01:50.020
If no items in the list match, then the last item in the list is used as a URI or an error code.

01:50.320 --> 01:57.610
For this location we'll use the URI variable to first look for a file that matches the URI being processed.

01:57.970 --> 02:04.270
Then we'll add the URI variable followed by a slash to test for any directories that might match.

02:04.630 --> 02:12.550
And lastly, we'll add equals 404 to tell engine X to serve a 404 error if no file or directory matches

02:12.550 --> 02:14.110
the URI being requested.

02:14.410 --> 02:20.590
Let's add another location for the images directory and in this location let's add the directive Auto

02:20.590 --> 02:24.340
index and use the keyword on the auto index directory.

02:24.340 --> 02:27.070
Will let the browser list the files in that directory.

02:27.400 --> 02:31.270
This means we'll be able to see the files in that directory from a browser.

02:31.570 --> 02:34.030
This behavior is turned off by default.

02:34.570 --> 02:39.340
And now let's add a couple more directives and locations for custom error pages.

02:39.670 --> 02:46.300
When Engine X can't find any content to respond to a request, it displays a 404 error page.

02:46.660 --> 02:51.880
And if there are any server side issues, Engine X will display a 500 error page.

02:52.240 --> 02:58.150
In these cases we've added an error page directive to tell engine X to use our custom pages instead

02:58.150 --> 02:59.140
of the defaults.

02:59.500 --> 03:05.620
For these custom pages, we've also added a location directive with an equal sign, also known as the

03:05.620 --> 03:07.330
exact match modifier.

03:07.690 --> 03:13.720
And inside the location block, we've added the internal directive which tells Engine X to process any

03:13.720 --> 03:17.860
redirects to the custom 404 page as an internal redirect.

03:18.190 --> 03:24.130
Both of these, the exact match modifier and the internal redirect will help Engine X serve our custom

03:24.130 --> 03:25.540
error page more quickly.

03:25.900 --> 03:28.390
Testing the 404 page will be easy.

03:28.390 --> 03:32.470
We can just request a page that we know our site isn't set up to serve.

03:32.740 --> 03:38.380
But since we don't have any server side processing in place, we need to add a specific location to

03:38.380 --> 03:40.240
test our 500 page.

03:40.570 --> 03:45.190
To do this, we can create a fake fast CGI pass that we know will fail.

03:45.580 --> 03:51.210
Okay, now let's save the file and exit and test the configuration with engine x dash dt.

03:51.580 --> 03:55.600
The configuration looks good so we can load it with system CTL.

03:55.600 --> 03:56.350
Reload.
