(1) Access_log is a Configuration item for the Ngx_http_log_module 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 on location, limit_except
Nginx access_log and log_format configuration items:
Log_format is used to define the log format and the name of the format.
Log_format defined under http:
Log_format my_access_log $remote _addr, $remote _user, $time _local, $request, $status, $bytes _sent, $http _referer, $http _ User_agent;
The access_log defined under HTTP controls the access log when no other access_log conditions are matched:
Access_log Logs/http_access.log My_access_log;
The access_log defined under location, which controls the access log when the URL contains the /hello/ path:
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;
}
Access the following pages from your browser:
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
the resulting 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
the resulting 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
for a complete description of Access_log, please refer to:
Http://nginx.org/en/docs/http/ngx_http_log_module.html
Nginx Learning Note 10HTTP Access log