WEBVTT

00:04.620 --> 00:10.800
Up to now we've dealt with and configured in genetics to serve static files of various types leaving

00:10.800 --> 00:16.470
the rendering of that file to be handled by the client or browser based on its content type or MIME

00:16.470 --> 00:17.430
type.

00:17.470 --> 00:23.520
Now while serving static files is great a critical part of most web servers is the ability to serve

00:23.550 --> 00:29.050
dynamic content that's been generated from a server side language such as P. HP.

00:29.100 --> 00:33.870
If you recall from the first section of this course I mentioned that engine X isn't able to embed its

00:33.870 --> 00:41.430
server side language processors so instead then we'll configure a standalone BHB service namely p p

00:41.430 --> 00:48.180
if P. M. to which engine X will pass the request for processing and then upon receiving the response

00:48.360 --> 00:52.380
typically has h.t. amelle return there to the client.

00:52.380 --> 00:56.060
This is essentially engine X functioning as a reverse proxy server.

00:56.160 --> 01:00.960
One of the strong points but we'll dig into that specific topic later on in the course.

01:00.960 --> 01:04.950
Step one then is to actually install the page b f P. M. service.

01:05.100 --> 01:08.170
We can safely use our package manager to do this.

01:08.220 --> 01:10.290
So again UPDATE AP t..

01:10.290 --> 01:11.770
Just good practice.

01:12.950 --> 01:21.860
And once that's done run apt get install the HP F. P. M. which will install the latest stable release

01:21.920 --> 01:30.860
of BHP fbm available to a peaty which we can see here happens to be BHB seven point one confirm.

01:30.860 --> 01:34.650
Fast forward through this and all done now.

01:34.670 --> 01:41.450
As with most services we install using a p t p s p f P. M. is very conveniently already configured as

01:41.450 --> 01:43.080
a system D service.

01:43.130 --> 01:49.980
Same as we've done for engine X which we can see happened year as Patch B seven point one dash F. P.

01:49.980 --> 01:50.670
M..

01:51.020 --> 01:53.880
Not just pitch b f be m as we installed it.

01:54.200 --> 01:59.690
This version number being a common naming convention of BHB just in order to have multiple versions

01:59.690 --> 02:00.980
in use at once.

02:00.980 --> 02:04.390
Should that be a requirement for development or testing.

02:04.430 --> 02:12.380
We can confirm that the service exists by listing all the system D services system C T L list units

02:12.710 --> 02:18.580
filtering the results with grep for anything containing be and there we have it.

02:18.620 --> 02:22.350
As expect it be B seven point one f P. M..

02:22.700 --> 02:28.420
Check the status of our newbie HP Service System C T L status.

02:28.480 --> 02:36.140
B seven point one dash F be M which is already running a single master process and two workers.

02:36.290 --> 02:42.770
So with B F be m running and ready to process page B requests Let's head over to engine next hour conf

02:42.800 --> 02:47.270
and configure the passing of our appear to be files to this service.

02:47.270 --> 02:51.460
First addition to this file is the inclusion of the index directive.

02:51.710 --> 02:57.950
This being a standard directive which tells engine X which file to load if the request point to a directory

02:58.450 --> 03:02.690
the default so the current value being indexed to HD moul.

03:02.900 --> 03:10.770
Hence why when we request our domain slash indexed or HDMI loads route Plus this index value.

03:11.060 --> 03:12.570
This like the try files.

03:12.580 --> 03:15.930
DirecTV can take multiple arguments in order of importance.

03:15.980 --> 03:22.670
So with the inclusion of BHB we'll typically want to serve index Dogpatch P first if it exists in a

03:22.670 --> 03:24.750
directory and if not.

03:24.750 --> 03:28.900
Secondly look for indexed or h.t. amelle the default.

03:28.910 --> 03:34.520
This by no means being a hard and fast rule but the most likely configuration when dealing with a to

03:34.520 --> 03:36.430
be based project.

03:36.470 --> 03:44.300
Next I'll get rid of this location create a new one for Slash So a prefix match for anything in which

03:44.300 --> 03:49.670
we're going to try it with try files the request that you are by then.

03:49.700 --> 03:56.420
Alternatively the requested you are I with an add a trailing slash in case it maps to a directory with

03:56.450 --> 04:00.110
either indexed of BHB or indexed dot aged here Mel.

04:00.140 --> 04:06.920
And finally if none of these exist go back to the default engine next foro for which we can write with

04:07.040 --> 04:09.210
equals forro for.

04:09.440 --> 04:13.250
So this location will take care of any requests for static content.

04:13.490 --> 04:19.580
Meaning that in a second location block using a regular expression match so it will take priority over

04:19.580 --> 04:20.920
this prefix match.

04:21.110 --> 04:27.410
We can match anything ending in dot BHB like so in order to pass a 2p edge.

04:27.410 --> 04:28.700
P if P. M..

04:29.420 --> 04:30.140
Which will do.

04:30.140 --> 04:33.450
By means of the fast CGI protocol.

04:33.590 --> 04:39.800
If you're not familiar with fast CGI I've linked to some information in the list and resources but essentially

04:39.800 --> 04:44.870
it's a protocol like HTP for transferring binary data.

04:44.930 --> 04:49.940
You don't need to understand this but just know that it's how engine X will communicate with B.

04:49.970 --> 04:51.270
B F p. m..

04:51.380 --> 04:54.760
We could have done this using the standard htb Protocol also.

04:54.860 --> 05:00.640
But fast CGI is slightly faster before we pass requests in this location context to be a.

05:00.680 --> 05:05.650
B f be m however we still need to include some other configuration parameters.

05:05.900 --> 05:08.270
Luckily as with our MIME types.

05:08.270 --> 05:14.780
Engine X provides a very good include with fast g.g. I preconfigured you might have spotted it during

05:14.780 --> 05:16.870
the installation but to double check.

05:16.880 --> 05:23.330
It's located at slash ATC slash engine X fast CGI dot conf.

05:23.570 --> 05:29.360
So in the same directory as the engine start con file meaning we can again just reference it relative

05:29.360 --> 05:38.720
to this file fast CGI dot conf then to pass this request to be a b f P. M. using fast e.g. I say FAST

05:38.740 --> 05:47.580
C I underscore pass and what we want to pass this to is a Unix socket created by page pfb M..

05:47.690 --> 05:54.280
Think of a socket as an HTP port a file on which a service can listen for binary data.

05:54.310 --> 05:57.560
Hence the use of fast CGI as a protocol.

05:57.620 --> 06:03.620
Again understanding the fast CGI protocol and Unix sockets is by no means required for understanding

06:03.620 --> 06:05.890
how to configure BHB within generics.

06:05.990 --> 06:11.240
But it's good to at least get an overall understanding of what's happening and why it's done like this

06:11.930 --> 06:14.450
to indicate that this endpoint is a Unix socket.

06:14.450 --> 06:20.510
Then we can say Unix colon and the location of that socket.

06:20.510 --> 06:27.810
In this case it's going to be located at slash run slash BHB slash BHB seven point one dash.

06:27.830 --> 06:29.800
If B M dot soc.

06:30.140 --> 06:34.460
I'll show you how to find the socket location for your install in a second.

06:34.460 --> 06:40.610
Save this over to the terminal and before we reload this engine XT configuration we can make sure the

06:40.750 --> 06:43.730
HP fbm socket is in fact at that location.

06:43.730 --> 06:47.600
By searching for it I'll use the find command.

06:47.600 --> 06:49.430
Look in the root of this machine.

06:49.430 --> 06:58.700
So searching everything by name and we'll search for any thing ending worth F be M dot shock enter and

06:58.700 --> 07:00.640
found at that exact location.

07:00.650 --> 07:06.820
As I've configured engine X so knowing that's correct reload engine X configuration.

07:07.280 --> 07:12.650
We still don't have any BHB files to test this worth so we'll create a simple test file.

07:12.650 --> 07:16.230
Just write the contents directly to our new page B file.

07:16.310 --> 07:27.860
Make it BHB opening statement calling BHB info close BHB to slash sites slash demo slash info Dogpatch

07:28.020 --> 07:29.010
be.

07:29.300 --> 07:34.070
If you're not familiar with BHB this is just saying start processing the content as patch.

07:34.070 --> 07:41.780
Be here call the BHB info function which is a native P P function for displaying all of page piece configuration

07:41.780 --> 07:47.900
information and stop processing BHB which wasn't really necessary as the file ends here.

07:47.920 --> 07:51.350
Anyway it over to the browser so we can test this.

07:51.500 --> 07:57.620
I'll just reload the demesne without any path and we get that same indexed to htl page from the demo

07:57.620 --> 07:58.790
directory.

07:58.790 --> 08:05.690
This of course being as we've named the BHB file info dot BHP meaning on this root directory request

08:05.840 --> 08:12.590
engineer is first checking for indexed or HP which isn't found then for indexed or HDL and serving the

08:12.590 --> 08:14.280
old demo page.

08:14.300 --> 08:16.990
This request also not containing a BHB extension.

08:17.000 --> 08:19.950
Hence not being matched on the BHB location.

08:20.780 --> 08:23.390
Change this request for info Dogpatch.

08:23.480 --> 08:30.930
However meaning will match on the BHB location and we get this error 5 0 too bad gateway.

08:31.190 --> 08:36.980
This being a prime example of when engine x error logs can really help out check the very last entry

08:36.980 --> 08:45.750
of the error log with tail and N flag one meaning one line of the end of this file var log.

08:45.770 --> 08:52.730
Engine x error log critical error connecting to Unix socket slash run slash B.

08:52.780 --> 08:53.680
B B.

08:53.690 --> 08:54.660
B seven point one.

08:54.680 --> 09:00.350
If B em sock with the reason engine x cannot connect to the socket being permission denied.

09:00.350 --> 09:02.650
A very common situation in this case.

09:02.780 --> 09:07.660
We can very quickly find the reason for this permissions error by checking the user with which the engine

09:07.660 --> 09:11.180
XT process is running the worker process here.

09:11.280 --> 09:20.860
Nobody which is the default for change and X and the p p if P. M. process w w w dashed data.

09:21.020 --> 09:26.430
Meaning this nobody user does not have permission to appear to be fbm socket.

09:26.510 --> 09:31.620
There is of course a number of ways we can solve this including changing the permissions of the socket.

09:31.700 --> 09:39.440
But the most secure and easiest way by far is to configure engine X to run as the same user w w w dash

09:39.440 --> 09:42.330
data in the configuration file.

09:42.350 --> 09:49.900
Simply add in the main context user w w w dashed data safe.

09:50.590 --> 09:52.390
Reload engine x.

09:53.700 --> 10:00.950
Check that process again which is now correctly running as w w w desch Data reload info Dogpatch.

10:00.960 --> 10:03.560
Be in the browser and it works.

10:03.570 --> 10:10.230
We get that full output of the BHB info function meaning engine X received the request matched it on

10:10.230 --> 10:13.200
the BHB location past that to the pier.

10:13.210 --> 10:19.500
B if B MS service where it was processed and passed back to engine X which in turn then served that

10:19.500 --> 10:21.500
processed response to us.

10:22.340 --> 10:28.300
One last point to cover is this index directive with indexed or appear to be as the priority.

10:28.300 --> 10:32.830
Let's create an index stoppage be file in that demo directory again.

10:32.840 --> 10:39.280
I'll write some content directly to at Echo a h one date.

10:39.590 --> 10:47.760
Then as beatch be echo the date function with a format of day of the week L..

10:47.870 --> 10:49.110
Day of the month.

10:49.130 --> 10:49.590
J.

10:49.610 --> 10:51.870
Capital S and month.

10:51.950 --> 10:52.700
F.

10:53.190 --> 10:53.850
End p.

10:53.880 --> 10:55.200
P processing.

10:55.410 --> 10:57.810
And close that each one statement.

10:57.810 --> 10:59.380
Writing there to slash sites.

10:59.400 --> 11:03.650
Slash demo slash indexed iph be back in the browser.

11:03.650 --> 11:05.540
Remove the request path.

11:05.670 --> 11:12.120
So previously serving indexed old h.t. a email and we get that indexed iph page instead.

11:12.210 --> 11:14.440
Meaning this indexed directive prioritized.

11:14.450 --> 11:21.090
Oh a new page B page over there h.t. a mail one that wraps up the basics of configuring a server side

11:21.090 --> 11:23.450
language process for INJ annexe.

11:23.520 --> 11:27.990
But be sure to check out all the links in the lesson and resources for more advanced configurations

11:28.020 --> 11:29.760
and implementations.
