nginx访问日志格式调整
1、配置在文件 nginx.conf 中。
2、可以配置为 josn 格式:
log_format json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"agent":"$http_user_agent",'
'"status":"$status"}';
3、配置日志 记录更多信息
log_format json '[v0.2] [$time_local] [$server_name] [$upstream_addr] [$remote_addr] [$http_x_forwarded_for] [$remote_user] [$status] [$bytes_sent] [$body_bytes_sent] [$request_length] [$request_time] [$upstream_response_time] [$request] [$http_referer] [$http_user_agent] [$connection_requests] [$request_body] [$http_cookie]';
对应的一条日志:
[v0.2] [11/Sep/2017:16:56:37 +0800] [139.198.1.207] [192.168.200.65:8090] [1.1.1.1] [-] [-] [200] [3604] [3248] [475] [0.002] [0.002] [GET /loginRegister/page/dypsdLogin.jsp HTTP/1.1] [http://192.168.0.1:1080/user/toDypsdLogin] [Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 MicroMessenger/6.5.2.501 NetType/WIFI WindowsWechat QBCore/3.43.27.400 QQBrowser/9.0.2524.400] [1] [-] [-]\n
对应: