Linux伺服器access_log日誌分析及配置詳解(一)

來源:互聯網
上載者:User

標籤:padding   服務   plain   大小   資訊   類型   版本   index   contain   

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

 其中access log 記錄了哪些使用者,哪些頁面以及使用者瀏覽器、ip和其他的訪問資訊

 error log 則是記錄伺服器錯誤日誌

 

錯誤記錄檔的形式如下:

12 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格式設定:

12345678910 #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;

 

Linux伺服器access_log日誌分析及配置詳解(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.