WEBVTT

00:00.110 --> 00:00.680
Hey, everyone.

00:00.680 --> 00:01.920
And welcome back.

00:01.940 --> 00:07.130
Now, in the earlier video, we had a great introduction about modular architecture.

00:07.160 --> 00:14.960
We also looked into how Nginx is built with the modular architecture and how that helps in enhancing

00:14.960 --> 00:17.720
the functionality of Nginx by itself.

00:17.840 --> 00:25.020
Now, till now we have been installing Nginx with a package manager like Yum or App.get.

00:25.040 --> 00:28.820
So those are ready made things that are being fed to us.

00:28.850 --> 00:36.380
However, in order to understand about the modular architecture, we need to learn on how we can compile

00:36.380 --> 00:37.940
Nginx from source.

00:38.060 --> 00:46.250
So for example, if I do a nginx hyphen V over here, so currently you see this Nginx has a lot of modules

00:46.250 --> 00:48.060
which are available over here.

00:48.080 --> 00:55.970
So many times we might need certain modules, we might not need certain modules, we might want to change

00:55.970 --> 00:58.190
the path associated with the binary.

00:58.190 --> 01:02.180
We might want to change the path associated with modules.

01:02.180 --> 01:04.820
So we want a lot of customization.

01:04.820 --> 01:13.130
So when you do so, like when you install Nginx via Yum or App.get, then your ability to customize

01:13.130 --> 01:15.110
each and everything is limited there.

01:15.110 --> 01:23.840
So in order to have a full capability of customization, you will have to compile Nginx from source.

01:23.840 --> 01:27.830
And this is what we will be looking in today's video.

01:28.190 --> 01:33.910
So for our demo purposes, I have a brand new server that I have created.

01:33.920 --> 01:40.310
So currently this does not have Nginx or any other package so that we can start from absolute scratch.

01:40.310 --> 01:45.200
So this is a CentOS seven based server now while compilation.

01:45.200 --> 01:50.570
So whenever you are compiling Nginx from source, there are certain packages that you will need as a

01:50.570 --> 01:51.560
prerequisite.

01:51.560 --> 01:56.990
So basically these are some of the important packages that we'll be using throughout our demo.

01:56.990 --> 02:03.690
So I have just created a document I'll be sharing the entire document after this video so that you can

02:03.690 --> 02:04.770
try it out yourself.

02:04.770 --> 02:09.540
So let me copy this up and I'll paste it within my terminal.

02:12.060 --> 02:12.690
Great.

02:12.690 --> 02:15.170
So our prerequisite is completed.

02:15.180 --> 02:19.860
Now the next thing that we need to do is we have to download the Nginx.

02:19.860 --> 02:23.010
So basically there are mainline versions.

02:23.010 --> 02:25.740
You have stable version, you have legacy version, legacy.

02:25.740 --> 02:28.380
Are the older ones, stable is the current stable.

02:28.380 --> 02:30.990
So in my case the stable is 1.16.

02:31.020 --> 02:36.630
In your case, if you are watching a video at a later stage, this version might change, but the overall

02:36.630 --> 02:38.430
procedure will remain the same.

02:38.430 --> 02:45.720
So I'll right click here, I'll click on copy link, address and within the terminal let's do a wget

02:46.320 --> 02:47.970
and I'll paste the link.

02:49.570 --> 02:53.410
So this will go ahead and download the tar file.

02:54.280 --> 02:57.760
So when I do an LS, this is the tar file.

02:57.910 --> 03:04.120
So let's go ahead and decompress it with tar xvf nginx.

03:05.500 --> 03:07.930
So it has decompressed it.

03:07.960 --> 03:12.860
Now if you do an ls, then you will be able to see the directory of nginx.

03:12.880 --> 03:15.700
So let's go inside the nginx directory here.

03:16.780 --> 03:18.280
And let's do an ls.

03:18.310 --> 03:21.400
So these are the files which are present.

03:21.430 --> 03:24.820
The one that is most important here is the configure file.

03:24.940 --> 03:33.240
So when I do a configure hyphen hyphen help you see there are various options which are available.

03:33.250 --> 03:35.490
So let's go a bit up.

03:35.500 --> 03:43.450
So basically here we while configuring, we can enable various modules like you have Http SSL module,

03:43.450 --> 03:47.090
you have Http version two module and various others.

03:47.110 --> 03:49.610
So there are a lot of modules which are available.

03:49.610 --> 03:55.670
So since we are doing things from scratch, all of these things are something that we will be able to

03:55.670 --> 03:58.880
modify according to the things that we need.

03:58.910 --> 03:59.660
All right.

03:59.840 --> 04:03.570
So the way things work are let me actually show you.

04:03.590 --> 04:05.300
Let me copy these things.

04:05.330 --> 04:05.620
All right.

04:05.630 --> 04:06.650
I'll copy this up.

04:06.950 --> 04:09.950
And within the atom editor, I'll paste it.

04:10.820 --> 04:11.450
All right.

04:11.780 --> 04:21.590
So now the way things would work here is you do a configure and various options which are specified

04:21.590 --> 04:22.150
over here.

04:22.160 --> 04:25.720
You have to mention the appropriate values for that.

04:25.730 --> 04:31.010
So for prefix, let's say you specify user share nginx.

04:31.130 --> 04:32.780
This is just an example.

04:32.870 --> 04:42.680
Then for sbin path, you specify this, you say user bin or user is bin and for modules port and so

04:42.680 --> 04:42.970
on.

04:42.980 --> 04:44.950
So this is how things would work.

04:44.960 --> 04:52.340
So generally in order to make things easy, we'll use the readymade values which are associated with

04:52.340 --> 04:53.240
these path.

04:54.950 --> 05:02.480
So when you look into the engine which was installed through Yum, there are already the values which

05:02.480 --> 05:03.980
are predefined.

05:04.010 --> 05:06.530
So we'll use the same values here.

05:06.560 --> 05:08.810
So what are the things that we need?

05:08.840 --> 05:10.370
We need prefix.

05:10.400 --> 05:12.300
We'll need SBN path.

05:12.320 --> 05:14.630
We'll need a module path.

05:14.660 --> 05:17.210
We'll also need the conf path.

05:17.840 --> 05:19.430
The error log path.

05:19.460 --> 05:21.590
The http log path.

05:22.730 --> 05:25.880
We'll also need the client body path here.

05:25.910 --> 05:26.270
All right.

05:26.270 --> 05:28.130
So these are the minimum things.

05:28.130 --> 05:30.050
So I'll just copy it up here.

05:30.050 --> 05:38.300
And along with that it is also recommended to make use of user specify the group.

05:38.300 --> 05:43.220
And while we are doing that, we also have to specify the PID path and the log path.

05:44.720 --> 05:46.530
So let's go back here.

05:46.550 --> 05:48.470
So here you have the PID path.

05:48.500 --> 05:55.140
You have the log path, you have the user as enginex and the group as Enginex.

05:55.140 --> 05:56.790
So I'll copy this up

05:59.790 --> 06:03.810
and within my atom editor I'll just paste them.

06:03.840 --> 06:04.620
All right.

06:04.890 --> 06:08.310
So this is how the configure command would look like.

06:08.520 --> 06:14.910
Now, apart from this, if you want to add a module here, you can definitely do that.

06:14.910 --> 06:18.690
So for our example, let's add one module.

06:18.690 --> 06:22.200
So I'll say with http mp4 module.

06:22.200 --> 06:25.110
So this is just an example that we are using here.

06:26.160 --> 06:30.510
So I'll specify with http, underscore MP4 module.

06:30.510 --> 06:34.290
So once you have this built, go ahead and configure this.

06:36.320 --> 06:38.380
So let me paste everything here.

06:38.390 --> 06:41.150
So this is the entire command that is being formed.

06:41.330 --> 06:49.430
Now, before we run this, do remember that there are certain things that you will have to create because

06:49.430 --> 06:55.570
currently here you see you have user is equal to nginx group is equal to Nginx.

06:55.580 --> 07:02.050
However, when you do an ID, you see the Nginx, no such user is there.

07:02.060 --> 07:07.120
So the user thinks are some of the parts that you will have to create.

07:07.130 --> 07:08.960
So let's go ahead and do it.

07:08.960 --> 07:11.120
I'll say user add Nginx.

07:11.720 --> 07:14.030
All right, so now we have the Nginx user.

07:14.030 --> 07:18.290
We'll also have to specify this specific directory path.

07:18.650 --> 07:28.490
So I'll copy this up and I'll say mkdir hyphen P I'll specify this path and I'll change the ownership

07:28.490 --> 07:33.350
so that the user nginx will be able to access this path.

07:33.380 --> 07:36.570
So I'll change the ownership to nginx.

07:39.070 --> 07:39.490
All right.

07:39.610 --> 07:45.370
Now, various other things can be automatically created by Nginx.

07:45.370 --> 07:48.730
So that is something that we don't have to worry much about.

07:48.730 --> 07:53.470
So with this said, let's go ahead and run the configure command.

07:57.740 --> 07:58.220
All right.

07:58.340 --> 08:02.630
So once this is done, you can go ahead and run, make command.

08:05.850 --> 08:09.600
And the last thing that we'll do is the make install command.

08:10.080 --> 08:10.860
Perfect.

08:10.860 --> 08:17.730
So once you have done that, you should be able to see the nginx directory and this Nginx directory

08:17.730 --> 08:20.640
has all the necessary configuration files.

08:20.670 --> 08:25.740
Now the next important thing is to make sure whether the enginex service is there or not.

08:25.770 --> 08:33.180
So when you do a systemctl status enginex you see that it is not able to find the Nginx service.

08:33.180 --> 08:36.840
So basically you will have to download this specific file.

08:37.110 --> 08:43.920
Now the official documentation already has this specific file and its contents, so these are the contents

08:43.920 --> 08:45.830
that we are interested in.

08:45.840 --> 08:50.370
So let's copy the path here and let's do a nano.

08:51.580 --> 08:54.370
And within here, we'll just paste the contents.

08:54.850 --> 08:56.770
Let's paste the content.

08:57.670 --> 08:58.270
All right.

08:58.300 --> 09:01.030
Now, we don't really have to edit here.

09:01.060 --> 09:09.760
Now, in case in case if you are not using the default values here, then you might have to edit the

09:09.790 --> 09:13.510
values associated within the service definition here.

09:13.540 --> 09:19.060
Now, since we are using the default path, we don't really have to do that and that is the advantage

09:19.060 --> 09:20.910
of using the default path.

09:20.920 --> 09:26.290
You don't have to worry much about the later stages, so I'll go ahead and I'll save it.

09:26.500 --> 09:30.670
So once it is done, let's verify whether the Nginx service is running.

09:30.700 --> 09:34.060
So it says that the Nginx service is inactive.

09:34.090 --> 09:36.970
All right, let's go ahead and start the Nginx service.

09:39.150 --> 09:42.360
And now let's do a status on Nginx.

09:43.680 --> 09:46.530
And you see the nginx is up and running.

09:46.560 --> 09:56.130
Now if you do a netstat on hyphen p you should see that the nginx is listening on port 80.

09:56.160 --> 10:01.440
So in order to quickly verify you can do a curl on 127001.

10:01.860 --> 10:05.970
You should be able to see the default nginx page.

10:05.970 --> 10:11.460
So if you want to also quickly verify, let's get the public IP address of this server.

10:12.630 --> 10:17.280
And when you paste it within the browser, you should be able to see the default.

10:17.280 --> 10:19.230
Welcome to Nginx page.

10:19.230 --> 10:25.170
So that's the high level overview about how you can compile Nginx from source.

10:25.200 --> 10:32.460
Now once you know on how you can compile nginx from source, then it will also be easier for you to

10:32.460 --> 10:36.870
understand the static as well as dynamic modules aspect.

10:36.900 --> 10:45.240
Now one last thing because when we do a nginx v hyphen here you see the output of this is much more

10:45.240 --> 10:50.940
less when you compare with the default Yum base installation.

10:52.530 --> 10:52.890
All right.

10:52.890 --> 10:54.690
So it is much more lesser.

10:54.690 --> 11:00.720
But one thing that you have to make sure that when you're running this in production environment, make

11:00.750 --> 11:07.590
sure that the functionality that you typically need within production, you have the appropriate modules

11:07.590 --> 11:08.220
for that.

11:08.250 --> 11:13.170
Otherwise, at a later stage, you will realize that you do not really have a module for a specific

11:13.170 --> 11:14.930
functionality that you are looking.

11:14.940 --> 11:23.010
So generally what many of the people they do, they directly just copy this entire thing and they remove

11:23.040 --> 11:26.050
certain modules which are not required.

11:26.100 --> 11:30.960
So for example, if you do not really require MP four, they'll just remove this.

11:30.960 --> 11:38.890
Otherwise most of the things people tend to keep it same as the one that comes from the package repository.

11:39.010 --> 11:47.350
So that's the high level overview about how you can compile Nginx from source and configure things according

11:47.380 --> 11:48.870
to your needs.

11:48.880 --> 11:50.980
So with this we'll conclude this video.

11:51.010 --> 11:54.850
I hope this video has been informative for you and I look forward to see you in the next video.
