WEBVTT

00:00.590 --> 00:07.670
In the last lecture we were talking about the basics of Nginx logging as well as we had an overview

00:07.670 --> 00:11.120
about the basics of Nginx access logs.

00:11.510 --> 00:13.640
So we'll continue with that.

00:13.640 --> 00:20.900
And in this video we'll have our own custom format for the logging facility as well as access log is

00:20.900 --> 00:21.530
concerned.

00:22.820 --> 00:25.150
So let's go to the Nginx logs.

00:26.200 --> 00:27.970
Or the Nginx configuration.

00:30.980 --> 00:31.370
I know.

00:31.450 --> 00:32.530
Nginx.conf.

00:34.220 --> 00:40.340
And before we go ahead, I just wanted to show you one more directive, which is access underscore log.

00:40.400 --> 00:48.770
So followed by the access underscore log is the file system location in which the log will be stored.

00:48.770 --> 00:49.970
So currently it is.

00:50.000 --> 00:52.100
Var log nginx access dot log.

00:52.100 --> 00:55.730
So this is something that you can change according to your environment.

00:56.510 --> 00:57.890
And one more.

00:59.140 --> 01:01.570
Directive which was present is the main.

01:01.570 --> 01:05.020
So the mean corresponds to the log format.

01:05.050 --> 01:06.040
Context.

01:06.190 --> 01:13.930
So if we have multiple log format sections, then we can actually mention the sections over here.

01:14.620 --> 01:18.310
So let's define one more context for the log format.

01:18.460 --> 01:21.670
So I'll say log underscore format.

01:27.040 --> 01:28.360
I'll name it master.

01:28.600 --> 01:34.750
And for this type of logs, I just need remote ADR.

01:37.180 --> 01:39.050
Followed by the status code.

01:39.070 --> 01:40.060
So I'll say.

01:44.050 --> 01:45.040
And.

01:46.490 --> 01:47.450
I'll change the.

01:48.500 --> 01:50.510
Context from main to master.

01:51.140 --> 01:53.780
So now the access log will be.

01:54.860 --> 02:00.200
Storing only two variables which are mentioned in the master context.

02:00.590 --> 02:02.360
So let me save the file.

02:02.390 --> 02:06.740
Let's check if everything is proper and let's reload the nginx.

02:09.570 --> 02:12.120
Okay, So go into that.

02:14.240 --> 02:14.510
Deal.

02:16.180 --> 02:18.790
Let's try to open example.com.

02:18.950 --> 02:19.810
I see jpeg.

02:22.050 --> 02:25.790
And it seems to be the cash.

02:25.800 --> 02:26.850
So let's.

02:28.920 --> 02:30.630
Do my seed one dot jpeg.

02:31.720 --> 02:33.100
And let's reload it.

02:35.540 --> 02:43.190
And now you see the format in which the log has been started to store is different.

02:43.220 --> 02:48.860
So here it is only showing the IP address of the client, followed by the response code.

02:48.860 --> 02:54.710
So first is 304 and second is 200, which directly corresponds to the.

02:56.220 --> 02:59.880
Format which we had written in the Nginx configuration file.

03:00.450 --> 03:07.410
So coming back to the Nginx.conf, so this is the format in which the access logs are stored.

03:08.830 --> 03:15.400
Now, one of the downsides of mentioning the format over here is that it is a global directive.

03:15.700 --> 03:23.620
So if you have multiple websites on a single server, all the website will start to store according

03:23.650 --> 03:26.560
to the master context.

03:26.830 --> 03:34.870
So what we if we want that website, one should store logs in the main format and website two should

03:34.870 --> 03:37.420
actually store logs based on master format.

03:37.450 --> 03:41.410
So this is a flexibility which nginx allows us to do.

03:41.440 --> 03:48.000
So we can actually specify this in the virtualhost configuration.

03:48.010 --> 03:50.380
So if I go to conf debconf.

03:51.490 --> 03:53.410
So below the server directive.

03:54.070 --> 03:56.230
If I mentioned access underscore log.

03:59.310 --> 04:01.980
I can also specify the custom location.

04:01.980 --> 04:09.510
So here if I say var log nginx example dot log followed by the context that we want.

04:09.540 --> 04:10.590
So I'll say main.

04:12.920 --> 04:17.390
And I'll verify and let's do a reload.

04:20.000 --> 04:20.420
Okay.

04:21.710 --> 04:24.740
So let me refresh the page.

04:26.960 --> 04:35.270
And now if you go to Var log Nginx, now you see there is a third file, which is example dot log which

04:35.270 --> 04:35.780
is stored.

04:36.470 --> 04:42.950
So if I do a less on example dot log here you will see the example.

04:42.950 --> 04:50.060
Dot log is actually storing the log in the format of main.

04:50.450 --> 04:53.000
Now let's close this.

04:54.110 --> 04:55.520
And let's modify.

04:59.430 --> 05:02.100
The webcomic again.

05:06.590 --> 05:12.860
Nginx conf debconf and let's modify it to master.

05:15.100 --> 05:16.800
The three road links.

05:18.740 --> 05:19.850
Let's do a tale.

05:23.870 --> 05:24.470
Sorry.

05:26.990 --> 05:28.670
On example log.

05:31.520 --> 05:35.060
Let's refresh the page from the browser.

05:35.630 --> 05:38.930
And now you see it is following the master format again.

05:39.500 --> 05:44.540
So this is the flexibility which Nginx allows us to give.

05:44.750 --> 05:48.870
First of all, we can define our own log format.

05:48.890 --> 05:55.130
It can be either global or it can even be a specific to a particular server location.

05:55.730 --> 05:57.710
So this is it about.

05:58.740 --> 06:00.260
The access logs.

06:00.270 --> 06:04.050
I hope this has been informative for you and I'd like to thank.
