Nginx log format and custom log Configuration
Nginx logs include access logs and error logs.
The access log records the users, pages, user browsers, ip addresses, and other access information.
The error log is used to record server error logs.
The error log format is as follows:
10.1.1.1--[22/Aug/2014: 16: 48: 14 + 0800] "POST/ajax/MbpRequest. do HTTP/1.1 "200 367"-"" Dalvik/1.6.0 (Linux; U; Android 4.1.1; ARMM7K Build/JRO03H) "" 119.189.56.175 "127.0.0.1: 8090 0.022 0.022
10.1.1.1--[22/Aug/2014: 16: 48: 19 + 0800] "POST/ajax/MbpRequest. do HTTP/1.1 "200 616"-"" Dalvik/1.6.0 (Linux; U; Android 4.0.4; GT-I9103 Build/IMM76D) "" 36.250.89.22 "127.0.0.1: 8090 0.036 0.036
We can see some information from the above:
1. Client (User) ip address. For example, 10.1.1.1 (intranet Server Load balancer address) in the preceding example)
2. Access time. For example, in the above example, [22/Aug/2014: 16: 48: 19 + 0800]
3. access port. For example, 127.0.0.1: 8080 in the above example
4. response time. For example, in the above example, 0.022
5. Request time. For example, in the above example, 0.022
6. User geographic location code (country code ).
7. host of the requested url address (target url address. For example,/... in the above example /....
8. Request Method (GET or POST ). For example, GET in the previous example
9. request url (remove the host part ). For example,/html/test.html in the above example
10. Request status (status code, 200 indicates success, 404 indicates that the page does not exist, 301 indicates permanent redirection, etc. The specific status code can be found online and will not be repeated ). For example, in the above example, "200"
11. Request page size. The default value is B (byte ). For example, in the above example, 2426
12. Source Page, that is, from which page to which the professional name is "referer ". For example: the "http://a.com" in the above example"
13. user browser language. For example, in the above example, "es-ES, es; q = 0.8"
14. Other information about the user's browser, such as the browser version and browser type. For example, in the above example, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.20.1.97 Safari/537.11"
In fact, the nginx access log format is not static and can be customized.
In the nginx. conf configuration file of nginx, find log_format, which is the log format.
Take a look at the log format settings that match the preceding logs:
# Access log format configuration. The specific parameters are not described in detail. As mentioned above, you can configure them as needed.
Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" "$ http_x_forwarded_for "'
'$ Upstream_addr $ upstream_response_time $ request_time ';
Access_log logs/access. log main;
# Configure the storage location and file of access log logs. Note: The access. log file can be split by date for easy viewing and processing.
Access_log/usr/local/nginx/log/access. log main;
Description
1. $ remote_addr and $ http_x_forwarded_for are used to record the Client IP address;
2. $ remote_user: used to record the client user name;
3. $ time_local: used to record the access time and time zone;
4. $ request: used to record the request url and http protocol;
5. $ status: used to record the Request status; success is 200,
6. $ body_bytes_s ent: record the size of the content sent to the client file subject;
7. $ http_referer: used to record access from that page Link;
8. $ http_user_agent: records information about the client browser;