其他配置ELK等步骤详情访问:
Apache2.4日志json格式化 | good good study,day day up~
nginx.conf
如下配置:
#略
log_format main
'remode_addr:$remote_addr - remote_user:$remote_user - time_local:[$time_local] - request:"$request" - '
'status:$status - body_bytes_sent:$body_bytes_sent - http_referer:"$http_referer" - '
'http_user_agent:"$http_user_agent" - http_x_forwarded_for:"$http_x_forwarded_for" - '
'http_host:$http_host - request_uri:$request_uri - ';
#默认main的日志格式
log_format json escape=json '{ "@timestamp": "$time_iso8601", '
'"time": "$time_iso8601", '
'"clientip": "$remote_addr", '
'"remote_user": "$remote_user", '
'"http_host": "$http_host",'
'"body_bytes_sent": "$body_bytes_sent", '
'"request_time": "$request_time", '
'"status": "$status", '
'"host": "$host", '
'"request": "$request", '
'"request_method": "$request_method", '
'"request_uri": "$request_uri",'
'"uri": "$uri", '
'"http_referrer": "$http_referer", '
'"body_bytes_sent":"$body_bytes_sent", '
'"http_x_forwarded_for": "$http_x_forwarded_for", '
'"http_user_agent": "$http_user_agent" '
'}';
#配置新的配置文件名为json,格式如上
access_log logs/access.log json;
#在将需要使用日志的地方配置使用新建名为json的日志格式。
参考资料:
Nginx 访问日志配置 - IT技术随笔 - 博客园
Module ngx_http_log_module
Apache2.4日志json格式化 | good good study,day day up~