Lodging facilities, something which is very important for any program.
So specifically, if you are a developer, you need log files to help you determine what exactly is
happening inside the program.
So as far as engineering is concerned, Nginx helps a great deal through its logs.
So let me give an example.
So through Nginx log, you can actually determine from which country the visitor is coming from.
What is the IP address of the visitor or what in website a visitor is trying to access.
You can also determine from which platform a visitor is coming from May, maybe Android, Windows Linux
and from which browser.
The.
Visitor is opening the website from.
So there are a lot of things that you can actually get from the logs.
So if you talk about Nginx logs, there are two types of logs.
One is the access log and one is the error log.
So in this video, we'll be talking more about the access logs.
So I'll just write access log.
So this is something that we'll cover in this chapter.
So Enginex basically writes information about the client request in the access log after the request
is processed.
So if this is a client so I'll say this is a client and this is a server.
So we already know Http is a request response based protocol.
So if a client sends a request to the Nginx engine, X will send some kind of a response back.
Now, this response will have some kind of a status code.
So maybe it is 200.
Okay.
Or it is for 404 or it is a 500 internal server error or so many other things.
Now, basically all of these is considered as some kind of a response.
So in access log.
Enginex will store the response.
Or you can say Enginex writes the information about the client request right after the request is processed.
So all of these information.
Is stored in the access log.
So let me give you an example for this.
So.
Let's minimize this.
And let's go back to the.
Logs.
So if I go to var log nginx.
Let's do a lon var log nginx.
And you find that there are two types of logs.
One is the access log and one is the error log.
So let's open access log and see what exactly is there in it.
Var log nginx access log.
So a lot of things on the basic overview, you can find that there is a IP address over here.
So just so you can find the IP address, you can find the date and time, you can find the type of request
get or post or whatever you want.
You can even find the browser as well as the operating system version.
And maybe this is a user agent string and so many other things.
So from this request.
And we can find that a client from this IP address at this time on 21st October, he tried to send a
get request using Http protocol 1.1.
And on that, the engineers gave a 404 response back.
That means Page not found.
So this is something that you can take out from the log files.
Now talking about access log, there is already a predetermined format through which a log file is stored.
So if we go to the Nginx configuration file.
So let's go below.
And if we look into the log underscore format.
Now log underscore format is a directive which is brought by the Nginx logging module.
So by default logging module is precompiled when you install nginx and that module brings the log underscore
format directive.
Now inside the log underscore format, we give a name of a format.
So this is main.
So this is something that you can change accordingly.
Followed by the name.
There are some variables which are being assigned.
Now, these variables correspond directly to the type of logs which are stored in the nginx.
So let's do a mapping.
So let me do a tail f on var log
nginx access log.
So this is something some this looks some kind of a hacking incident which people are trying to make
on the server.
Anyways, so we'll talk about security maybe sometime later.
Let's say let me open this.
My jpeg and the image is loaded.
So if you go inside the log, you see this is the.
Log format.
So let's open.
Let's split the screen so that we can actually determine on what exactly these times these fields are.
So let me split the screens and let's do a vertical split.
Okay.
So.
Actually, I did.
Yeah.
So this seems much more better since we are able to read the entire log file.
So let me go down.
Okay.
So the first portion of the access log is the variable remote addr.
So remote addr basically is the IP address of the client who is trying to connect.
So here you see the first field that you will find over here is the remote addr field, which is the
IP address.
Followed by the remote.
ADR is a hyphen, so you'll see a hyphen over here.
Then is a variable remote underscore user.
Now remote underscore user is basically a field.
When you do a Http basic authentication.
So in Http basic authentication, we provide a username and a password.
So this variable corresponds to the username as there is no basic authentication.
You will find that your you are going to have a hyphen.
I just messed up.
Let's clear the screen.
And let's open the log file again.
Okay.
So after remote underscore user there is time underscore local.
So basically this is the timestamp, the time in which the request has come.
So here we see the timestamp, which is 12th November 2015 at 629.
So followed by the timestamp.
There is a request field, so request corresponds to the request that the client is sending or the Uri.
So here it is saying get followed by my Jpeg.
Now we've already seen different type of request headers which can be get post head options and so many
other things.
Also followed by that is the Http protocol version, which is either 1.0 or 1.1.
Now after the request.
Variable that is status variable.
So status is the response status, which can be 200, 400 or 500.
So here you see it is a 200 status.
So means this request is processed successfully.
Followed by the status.
It is a body bytes set.
So this is the size of the response which Enginex has.
Send it back to the client.
Then we have a Http referrer field which is empty because the user has directly opened the website from
the browser.
After the Http referrer field, there is something called as the Http user agent field.
So user Agent Field basically tells about the browser.
And the operating system sometimes that the client is.
Accessing the page from.
So from here we can see the client is trying to access this particular request from Mozilla browser,
followed by the version number as well, which is Firefox 33.
And the last field here is http x-forwarded-for.
So x-forwarded-for is something which is useful when there is a proxy in between.
So this is something that you can determine now.
You can always change these variables according to the needs that you have.
So if you do not want.
Say body underscore bytes, underscore set variable, then you can always remove that and it will be
reflected in your logs.
Again, you can always add new variables if you want.
Depending upon the type of access log that you want to have.
So this is in simple a generic overview about the Nginx access log.
I hope this has been informative for you and I'd like to thank you for viewing.