歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> nginx access 日志分析及配置

nginx access 日志分析及配置

日期:2017/3/1 11:40:58   编辑:關於Linux

nginx access 日志分析及配置

nginx的log日志分為access log 和 error log

其中access log 記錄了哪些用戶,哪些頁面以及用戶浏覽器、ip和其他的訪問信息

error log 則是記錄服務器錯誤日志

錯誤日志的形式如下:

1 2 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"

從上面我們可以看出幾部分信息:

1.客戶端(用戶)IP地址。如:上例中的 201.158.69.116

2.訪問時間。如:上例中的 [03/Jan/2013:21:17:20 -0600]

3.訪問端口。如:上例中的 127.0.0.1:9000

4.響應時間。如:上例中的 0.007

5.請求時間。如:上例中的 0.007

6.用戶地理位置代碼(國家代碼)。如:上例中的 MX(墨西哥)

7.請求的url地址(目標url地址)的host。如:上例中的 pythontab.com

8.請求方式(GET或者POST等)。如:上例中的 GET

9.請求url地址(去除host部分)。如:上例中的 /html/test.html

10.請求狀態(狀態碼,200表示成功,404表示頁面不存在,301表示永久重定向等,具體狀態碼可以在網上找相關文章,不再贅述)。如:上例中的 "200"

11.請求頁面大小,默認為B(byte)。如:上例中的 2426

12.來源頁面,即從哪個頁面轉到本頁,專業名稱叫做“referer”。如:上例中的 "http://a.com"

13.用戶浏覽器語言。如:上例中的 "es-ES,es;q=0.8"

14.用戶浏覽器其他信息,浏覽器版本、浏覽器類型等。如:上例中的 "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11"

其實nginx access日志的格式不是一成不變的,是可以自定義的。

在nginx的nginx.conf配置文件找到:log_format 這裡就是日志的格式

看一下和上述日志匹配的log格式設置:

1 2 3 4 5 6 7 8 9 10 #access日志格式配置,具體參數不再細說,上面都已經說過了,自己對應一下即可 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" '; #配置access log日志的存儲位置及文件,注意:access.log文件是可以按日期進行分割的,方便查看及處理 access_log /home/serversoft/nginx/log/access.log main;
Copyright © Linux教程網 All Rights Reserved