In the last lecture we were talking about the basics of Nginx logging as well as we had an overview
about the basics of Nginx access logs.
So we'll continue with that.
And in this video we'll have our own custom format for the logging facility as well as access log is
concerned.
So let's go to the Nginx logs.
Or the Nginx configuration.
I know.
Nginx.conf.
And before we go ahead, I just wanted to show you one more directive, which is access underscore log.
So followed by the access underscore log is the file system location in which the log will be stored.
So currently it is.
Var log nginx access dot log.
So this is something that you can change according to your environment.
And one more.
Directive which was present is the main.
So the mean corresponds to the log format.
Context.
So if we have multiple log format sections, then we can actually mention the sections over here.
So let's define one more context for the log format.
So I'll say log underscore format.
I'll name it master.
And for this type of logs, I just need remote ADR.
Followed by the status code.
So I'll say.
And.
I'll change the.
Context from main to master.
So now the access log will be.
Storing only two variables which are mentioned in the master context.
So let me save the file.
Let's check if everything is proper and let's reload the nginx.
Okay, So go into that.
Deal.
Let's try to open example.com.
I see jpeg.
And it seems to be the cash.
So let's.
Do my seed one dot jpeg.
And let's reload it.
And now you see the format in which the log has been started to store is different.
So here it is only showing the IP address of the client, followed by the response code.
So first is 304 and second is 200, which directly corresponds to the.
Format which we had written in the Nginx configuration file.
So coming back to the Nginx.conf, so this is the format in which the access logs are stored.
Now, one of the downsides of mentioning the format over here is that it is a global directive.
So if you have multiple websites on a single server, all the website will start to store according
to the master context.
So what we if we want that website, one should store logs in the main format and website two should
actually store logs based on master format.
So this is a flexibility which nginx allows us to do.
So we can actually specify this in the virtualhost configuration.
So if I go to conf debconf.
So below the server directive.
If I mentioned access underscore log.
I can also specify the custom location.
So here if I say var log nginx example dot log followed by the context that we want.
So I'll say main.
And I'll verify and let's do a reload.
Okay.
So let me refresh the page.
And now if you go to Var log Nginx, now you see there is a third file, which is example dot log which
is stored.
So if I do a less on example dot log here you will see the example.
Dot log is actually storing the log in the format of main.
Now let's close this.
And let's modify.
The webcomic again.
Nginx conf debconf and let's modify it to master.
The three road links.
Let's do a tale.
Sorry.
On example log.
Let's refresh the page from the browser.
And now you see it is following the master format again.
So this is the flexibility which Nginx allows us to give.
First of all, we can define our own log format.
It can be either global or it can even be a specific to a particular server location.
So this is it about.
The access logs.
I hope this has been informative for you and I'd like to thank.