Nginx学习笔记10HTTP访问日志
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx学习笔记10HTTP访问日志相关的知识,希望对你有一定的参考价值。
(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访问日志的主要内容,如果未能解决你的问题,请参考以下文章