前言
nginx的log日志分為:access/42180.html">access log 和 error log
其中access log 記錄了哪些用戶,哪些頁面以及用戶瀏覽器、ip和其他的訪問信息
error log 則是記錄服務器錯誤日志
log_format 日志格式語法:
log_format name(格式名字) 格式樣式(即想要得到什么樣的日志內容)
示例:
log_format main '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_s ent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"'
錯誤日志的形式如下:
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格式設置:
#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;
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網的支持。
新聞熱點
疑難解答