首页 > Web开发 > 详细

Nginx打印json日志

时间:2019-10-12 19:18:58      阅读:101      评论:0      收藏:0      [点我收藏+]

1.修改配置,在http{}中添加

log_format access_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",‘
                           ‘"domain":"$host",‘
                           ‘"xff":"$http_x_forwarded_for",‘
                           ‘"referer":"$http_referer",‘
                           ‘"status":"$status"}‘;
access_log  /var/log/nginx/access.log  access_json;

 技术分享图片

 

 2.重启

systemctl restart nginx

或者

nginx -s reload

3.访问,输出日志

{"@timestamp":"2019-10-12T18:41:48+08:00","host":"127.0.0.1","clientip":"127.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"localhost","url":"/index.html","domain":"localhost","xff":"-","referer":"-","status":"304"}

 

Nginx打印json日志

原文:https://www.cnblogs.com/tonglin0325/p/11663364.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!