Nginx學習筆記10HTTP訪問日誌

來源:互聯網
上載者:User

標籤:server   real-ip   favicon   family   span   window   user   eve   resource   

(1)access_log是ngx_http_log_module模組的配置項。

 

Syntax: access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];

access_log off;

Default:

access_log logs/access.log combined;

Context: http, server, location, if in location, limit_except

 

Nginx的access_log和log_format配置項:

log_format用於定義日誌格式以及該格式的名稱。

http下定義的log_format:

 

log_format  my_access_log $remote_addr,$remote_user,$time_local,$request,$status,$bytes_sent,$http_referer,$http_user_agent;

 

http下定義的access_log,控制在無法匹配其它access_log條件的時候的訪問日誌:

    access_log logs/http_access.log  my_access_log;

 

 

location下定義的access_log,控制在URL包含/hello/路徑時的訪問日誌:

location ~  ^/hello/ {

             proxy_pass  http://tomcat101.coe2coe.me:8080;

             proxy_set_header X-Real-IP  $remote_addr;

             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

 

            access_log logs/http_hello_access.log  my_access_log;

 

    }

 

 

通過瀏覽器訪問以下頁面:

http://ng.coe2coe.me:8000/hello/

http://ng.coe2coe.me:8000/hello/

http://ng.coe2coe.me:8000/hello/?a=1&b=2&c=3

http://ng.coe2coe.me:8000/abc/?a=1&b=2&c=3

 

產生的http_acess.log:

20.1.1.11,-,02/Jul/2017:10:57:37 +0800,GET /favicon.ico HTTP/1.1,200,1592,http://ng.coe2coe.me:8000/hello/,Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36

20.1.1.11,-,02/Jul/2017:11:12:05 +0800,GET /abc/?a=1&b=2&c=3 HTTP/1.1,403,726,-,Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36

 

 

產生的http_hello_access.log:

20.1.1.11,-,02/Jul/2017:10:57:37 +0800,GET /hello/ HTTP/1.1,200,3957,http://ng.coe2coe.me:8000/hello/,Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36

20.1.1.11,-,02/Jul/2017:10:57:37 +0800,GET /hello/resources/test.jpg HTTP/1.1,200,10277,http://ng.coe2coe.me:8000/hello/,Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36

20.1.1.11,-,02/Jul/2017:10:57:40 +0800,GET /hello/ HTTP/1.1,200,3852,http://ng.coe2coe.me:8000/hello/,Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36

20.1.1.11,-,02/Jul/2017:11:06:56 +0800,GET /hello/?a=1&b=2&c=3 HTTP/1.1,200,3757,-,Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.86 Safari/537.36

 

 

access_log相關的完整介紹,請參考:

 

http://nginx.org/en/docs/http/ngx_http_log_module.html

 

Nginx學習筆記10HTTP訪問日誌

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.