WEBVTT

00:00.200 --> 00:00.710
Hey, everyone.

00:00.710 --> 00:01.600
And welcome back.

00:01.610 --> 00:07.550
Now, in today's video, we will be discussing about the include directive that is part of the Http

00:07.550 --> 00:09.950
context in Nginx configuration file.

00:09.950 --> 00:14.780
Now, if you look into the Http context, that is part of the Nginx.conf file.

00:14.780 --> 00:18.290
It basically contains the default parameters over here.

00:18.320 --> 00:23.960
Now when you work in a production environment, you can have multiple websites that are running on top

00:23.960 --> 00:24.620
of Nginx.

00:24.620 --> 00:30.530
Now when you have multiple websites, then you will have to specify the associated configuration in

00:30.530 --> 00:32.540
this specific Http context.

00:32.540 --> 00:38.510
Block And soon what will happen in production environment is that this context block becomes very big

00:38.510 --> 00:42.050
and it also becomes a little difficult to manage.

00:42.050 --> 00:50.000
And hence it is recommended that instead of adding new configuration in the default nginx.conf file

00:50.000 --> 00:55.970
under the Http context, what you can do, you can basically make use of a include directive.

00:55.970 --> 01:01.140
So include directive allows us to include another file into a configuration.

01:01.140 --> 01:07.770
For example, you have include here followed by Nginx.conf dot de start conf.

01:07.770 --> 01:14.070
So now what will happen is any configuration that you specify under this specific directory in a file

01:14.100 --> 01:21.900
of star dot conf, those configurations will be added as part of this http context without manually

01:21.900 --> 01:25.140
modifying this specific nginx.conf file.

01:25.140 --> 01:27.560
So this is the basics of include directive.

01:27.570 --> 01:29.520
Let's go ahead and explore this.

01:29.520 --> 01:34.020
So let's do a quick cat on the nginx.conf.

01:34.020 --> 01:40.590
And in this Http context here you have a directory of include followed by the path.

01:40.590 --> 01:44.520
The path is e.t.c., nginx.conf dot d star conf.

01:44.520 --> 01:50.490
So basically any file in the conf directory which has the extension of dot conf.

01:50.490 --> 01:53.640
So if I quickly do an ls hyphen l.

01:53.640 --> 02:00.030
So basically currently we are within the e.t.c. enginex directory and within this directory we have

02:00.030 --> 02:01.880
a conf dot d directory.

02:02.190 --> 02:09.750
So let's quickly go to conf directory and if I do an ls you have a default dot conf file.

02:09.750 --> 02:16.560
So whenever a nginx starts it will also load the configuration that is part of this default dot conf.

02:16.560 --> 02:23.130
Now if you quickly do a cat on default dot conf, one thing that you will see is a server block.

02:23.130 --> 02:29.760
Now this server block is very important primarily because here you define various nginx configuration

02:29.760 --> 02:38.310
specific data like what is the port where the nginx should listen from, where should it load the index.html

02:38.310 --> 02:38.580
file?

02:38.580 --> 02:45.810
For example, when you open up the website in the browser, this is the HTML file that is being loaded.

02:45.810 --> 02:49.620
Now from where exactly is this HTML file coming from?

02:49.620 --> 02:51.510
So that is what is defined here.

02:51.510 --> 02:57.030
So under the location you have specified the directory which is usr share nginx.

02:57.180 --> 03:04.830
HTML and under this directory this is the index.html file whose contents are being displayed over here.

03:04.830 --> 03:12.900
So instead of adding all of these details under the main nginx.conf, the developers have added it under

03:12.900 --> 03:18.120
the default dot conf and within here you can specify all of the required details.

03:18.120 --> 03:25.530
For example, let's do one thing, let's go ahead and modify this default dot conf over here and let's

03:25.530 --> 03:27.810
go ahead and remove this curly braces.

03:28.230 --> 03:29.010
All right.

03:29.040 --> 03:34.740
Now we have not really touched the Nginx.conf which is the main enginex configuration file.

03:34.740 --> 03:42.570
Now if you do a nginx hyphen t immediately you see you got an error stating that a curly braces is missing

03:42.570 --> 03:44.160
in the default dot conf.

03:44.160 --> 03:51.210
So whenever you do a nginx hyphen t or whenever you restart nginx nginx will not only go ahead and load

03:51.210 --> 03:58.080
the nginx.conf but also all of the configuration files that are part of the include directive.

03:58.080 --> 04:02.490
So let's go ahead and change back and fix the file.

04:02.490 --> 04:08.430
So now if you do a nginx hyphen t things seems to be working perfectly well in a similar way.

04:08.430 --> 04:13.080
If you just create a random file, let's just call it as temp dot conf.

04:13.200 --> 04:15.870
And I'll just add a curly brace here.

04:15.870 --> 04:22.800
Now if I do a hyphen t again immediately you see you got an error associated with the temp dot conf

04:22.800 --> 04:28.590
and this error was primarily because let's first go ahead and remove the temp conf here.

04:29.280 --> 04:33.060
Let's go back and let's open up the nginx.conf.

04:33.060 --> 04:40.650
And the error was primarily because all of the files that are ending with the dot conf extension under

04:40.650 --> 04:43.410
this specific directory will be loaded.

04:43.410 --> 04:49.680
And since we had a file called as temp dot conf, even the configurations that were part of it got loaded.

04:49.680 --> 04:50.190
All right.

04:50.190 --> 04:55.380
So I hope you understood the importance of the include directive in production environment.

04:55.380 --> 04:59.850
You will not really be touching this specific section extensively.

04:59.980 --> 05:00.880
What you will be doing.

05:00.910 --> 05:07.420
You will be going ahead and going to the cornfield and depending upon the website and its associated

05:07.420 --> 05:13.450
configuration you need, you will be creating your own configuration file or maybe modifying the default

05:13.660 --> 05:14.980
conf accordingly.

05:15.010 --> 05:15.670
All right.

05:15.670 --> 05:21.460
So just to revise the workflow, you have a nginx.conf, you include multiple files, let's say custom

05:21.460 --> 05:24.550
01.02. conf and so on.

05:24.550 --> 05:31.780
And ultimately nginx final configuration would be the nginx.conf along with the custom zero one conf

05:31.780 --> 05:37.810
custom zero two conf and depending upon the configuration nginx will go ahead and work accordingly.

05:37.810 --> 05:40.300
So that's the basics of the include directive.

05:40.300 --> 05:42.550
And with this we'll conclude today's video.
