在做大数据分析的时候,需要收集nginx日志,常用json格式,默认nginx日志不方便处理
nginx.conf
http {
include mime.types;
default_type application/octet-stream;
# 原有日志格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time';
# json日志格式
log_format log_json '{"@timestamp": "$time_local", '
'"remote_addr": "$remote_addr", '
'"referer": "$http_referer", '
'"request": "$request", '
'"status": $status, '
'"bytes": $body_bytes_sent, '
'"agent": "$http_user_agent", '
'"x_forwarded": "$http_x_forwarded_for", '
'"up_addr": "$upstream_addr",'
'"up_host": "$upstream_http_host",'
'"up_resp_time": "$upstream_response_time",'
'"request_time": "$request_time"'
' }';
access_log logs/access.log log_json; # 引用日志格式名称
...
删除原来的 access.log
重新启动nginx
/usr/local/nginx/sbin/nginx -s reload
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://blog.csdn.net/zx77588023/article/details/123079087
内容来源于网络,如有侵权,请联系作者删除!