Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of access_log Log in nginx Server

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the nginx server access_log sample analysis, the article is very detailed, has a certain reference value, interested friends must read!

preface

nginx logs are divided into: access log and error log

The access log records which users, which pages, and the user's browser, ip, and other access information

error log is a log of server errors.

log_format Log format syntax:

log_format name Format style (i.e. what kind of log content you want)

Examples:

log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_s ent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"'

The error log takes the following form:

201.158.69.116 - - [03/Jan/2013:21:17:20 -0600] fwf[-] tip[-] 127.0.0.1:9000 0.007 0.007 MX pythontab.com GET /html/test.html HTTP/1.1 "200" 2426 "http://a.com" "es-ES,es;q=0.8" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"187.171.69.177 - - [03/Jan/2013:21:17:20 -0600] fwf[-] tip[-] 127.0.0.1:9000 0.006 0.006 MX pythontab.com GET /html/test2.html HTTP/1.1 "200" 2426 "http://a.com" "es-ES,es;q=0.8" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"

From the above we can see several pieces of information:

1. Client (user) IP address. For example: 201.158.69.116 in the above example

2. Visit time. For example: [03/Jan/2013:21:17:20 -0600] in the above example

3. Access port. For example: 127.0.0.1:9000 in the above example

4. Response time. 0.007 in the above example

5. Request time. 0.007 in the above example

6. User geographic location code (country code). For example: MX (Mexico) in the above example

7. Host of the url address of the request (destination url address). For example: pythontab.com in the above example

8. Request method (GET or POST). For example: GET in the above example

9. Request url address (remove host). For example: the above example in the/html/test.html

10. Request status (status code, 200 means success, 404 means page does not exist, 301 means permanent redirection, etc., specific status code can be found on the Internet related articles, no longer repeated). For example: "200" in the above example

11. The requested page size defaults to B (byte). 2426 in the above example.

12. The source page, i.e. the page from which to go to this page, is technically called "referrer." For example: "http://a.com"in the above example

13. User browser language. For example: "es-ES,es;q=0.8" in the above example

14. Other information about the user browser, browser version, browser type, etc. Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11

In fact, the format of nginx access logs is not static, it can be customized.

In nginx's nginx.conf configuration file find: log_format Here is the log format

Take a look at the log formatting that matches the log above:

#access log format configuration, the specific parameters are not detailed, as mentioned above, you can log_format main '$remote_addr - $remote_user [$time_local] ' 'fwf[$http_x_forwarded_for] tip[$http_true_client_ip] ' '$upstream_addr $upstream_response_time $request_time ' '$geoip_country_code ' '$http_host $request ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_accept_language" "$http_user_agent" ';#Configure the storage location and file of the access log. Note: the access.log file can be divided by date to facilitate viewing and processing access_log/home/serversoft/nginx/log/access.log main; The above is "Sample analysis of access_log logs in nginx servers" All the contents of this article, thank you for reading! Hope to share the content to help everyone, more relevant knowledge, welcome to pay attention to the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report