WEBVTT

00:00.110 --> 00:00.540
Here.

00:00.650 --> 00:01.520
And welcome back.

00:01.520 --> 00:06.710
In today's video, we will look into how we can build static modules in Nginx.

00:06.740 --> 00:14.180
Now, we have already looked about how the dynamic modules work practically in Nginx, where you first

00:14.180 --> 00:20.540
compile the module and then you reference it with a load module directive followed by the module path.

00:20.540 --> 00:22.550
So this was pretty straightforward.

00:22.550 --> 00:28.460
And in dynamic configuration you don't really have to recompile your nginx version.

00:28.460 --> 00:31.490
So your Nginx version in production remains the same.

00:31.490 --> 00:37.460
The only thing that you're doing is you're compiling the module by itself and then referencing it within

00:37.460 --> 00:39.020
the nginx configuration.

00:39.020 --> 00:42.290
So the nginx binary remains untouched.

00:42.320 --> 00:46.040
However, in static modules things are a little different.

00:46.040 --> 00:53.390
So static modules are compiled into the Nginx server binary at compile time.

00:53.390 --> 00:59.360
So whenever you are compiling your Nginx, you have to reference the module there.

00:59.360 --> 01:02.280
Whenever you are discussing about the static modules.

01:02.280 --> 01:09.240
So it is not like you already have the nginx binary compiled and running in production and then you

01:09.240 --> 01:10.980
want to add one more module there.

01:10.980 --> 01:15.840
So as far as static modules are concerned, that really is not really the approach there.

01:15.840 --> 01:19.670
So let's look into the steps which are required for building static modules.

01:19.680 --> 01:25.380
First is to fetch the Nginx source, second is to fetch the module source.

01:25.380 --> 01:32.610
So this two step remains similar and the step three is to build the static module along with Nginx.

01:32.640 --> 01:36.180
Now for dynamic module we only use to build dynamic module.

01:36.180 --> 01:42.750
However, for static module you will have to build the nginx itself because here the nginx is also compiled.

01:42.750 --> 01:45.540
So let's look into the steps which are required.

01:45.540 --> 01:45.870
Now.

01:45.870 --> 01:48.990
In the previous video we had built the dynamic module.

01:48.990 --> 01:54.930
Now if you do a nginx hyphen V, you will not really see that specific helloworld module because it

01:54.930 --> 02:00.930
is dynamic and whatever module that you generally reference, here are the static modules.

02:00.930 --> 02:04.350
So in today's video we'll be building static modules.

02:04.350 --> 02:06.900
So in order to do that, let's do one thing.

02:06.900 --> 02:09.360
Let's quickly verify the status of Nginx.

02:09.360 --> 02:10.380
It is running.

02:10.890 --> 02:22.590
I'll stop the Nginx service and I'll remove the Nginx directory and I'll also remove the nginx binary

02:22.590 --> 02:23.450
by itself.

02:23.460 --> 02:25.230
All right, great.

02:25.410 --> 02:29.490
So now let's go to the Nginx demo directory.

02:29.490 --> 02:38.100
We'll go to Nginx one point 16.0 and here during the configuration option we'll use the same configuration

02:38.100 --> 02:44.010
option which you remember we had done while building Nginx from source.

02:44.010 --> 02:48.360
So while compiling Nginx from source we had run this specific command.

02:48.360 --> 02:50.250
We'll use the same command here.

02:50.430 --> 02:55.530
In addition, we have to also specify the static module here.

02:55.680 --> 03:01.260
Now, basically if you look into the Hello world we already discussed about the dynamic module this

03:01.260 --> 03:03.720
time we have to see the static module.

03:03.720 --> 03:08.220
So the static module here, the only difference is you remove the dynamic here.

03:08.220 --> 03:11.550
So this is Add module followed by the module path.

03:11.550 --> 03:16.260
And for dynamic module you have add dynamic module followed by the module path.

03:16.260 --> 03:19.050
And basically this command remains the same.

03:19.050 --> 03:21.960
It is not just specific to the Hello World module.

03:21.960 --> 03:26.280
Any other module you will build, the overall process remains the same.

03:26.280 --> 03:31.410
The only thing that will change is the config file here as well as the module file.

03:31.410 --> 03:33.450
So let's try this out.

03:33.450 --> 03:41.490
So I'll say hyphen, hyphen hyphen module and let's specify the module path which is.

03:44.640 --> 03:45.650
Let's go better.

03:45.660 --> 03:50.040
Let's get the exact directory name where the module config is present.

03:53.270 --> 03:53.600
All right.

03:53.600 --> 03:55.330
So this is the exact path.

03:55.340 --> 03:58.790
So now together, we'll copy this entire command.

03:58.820 --> 04:02.870
We'll go back to the Nginx source directory and we'll run this command.

04:04.580 --> 04:11.600
So this will go ahead and not only build your nginx binary, but this binary will have the static module

04:11.600 --> 04:13.050
that we had referenced.

04:13.070 --> 04:15.710
So the next command would be make.

04:16.970 --> 04:19.490
And the last command would be make install.

04:20.960 --> 04:21.520
Great.

04:21.530 --> 04:27.280
So now if you go to the Nginx directory, these are the configuration files.

04:27.290 --> 04:29.810
Let's go ahead and start Nginx.

04:30.980 --> 04:31.340
All right.

04:31.340 --> 04:37.970
And if you do a nginx hyphen v here, you will see that there is one more parameter which is add module

04:37.970 --> 04:40.910
which is your Hello world module here.

04:41.150 --> 04:47.990
So now you don't really have to do a load module directive that we had done typically during the dynamic

04:47.990 --> 04:48.780
module time.

04:48.830 --> 04:55.170
So in order to verify, let's open up the Nginx configuration and let's go a bit down and we'll copy

04:55.170 --> 04:58.930
the same server block that we had used during the dynamic module.

04:58.950 --> 05:01.920
So this is the same server block that we had used.

05:01.950 --> 05:04.380
Now here we are not doing load module.

05:04.950 --> 05:06.960
So now let's quickly verify.

05:07.170 --> 05:09.350
Everything seems to be working perfectly.

05:09.390 --> 05:11.100
Let's restart Nginx.

05:11.700 --> 05:12.450
All right.

05:12.450 --> 05:19.880
So now if you do a curl on localhost colon 8080, you should see hello world as expected.

05:19.890 --> 05:26.940
So I hope at a high level overview you understood what static modules are and you also understood what

05:26.940 --> 05:28.120
dynamic modules are.

05:28.140 --> 05:30.960
So with this, we'll conclude this video.

05:30.990 --> 05:34.920
I hope this video has been informative for you and I look forward to see you in the next video.
