码迷,mamicode.com
首页 > Web开发 > 详细

更改Nginx日志为json格式

时间:2019-06-04 16:08:48      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:window   logs   body   gecko   set   json   orm   rem   amp   

  Nginx是最常用的web服务器,其可以承受的并发访问量远远大于apache,通过将nginx保存为json格式,然后对日志进行分析展示,能够获取到很多更直观的信息,然后加以统计,可以进行更多的数据展示。

    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",‘
        ‘"uri":"$uri",‘
        ‘"domain":"$host",‘
        ‘"xff":"$http_x_forwarded_for",‘
        ‘"referer":"$http_referer",‘
        ‘"tcp_xff":"$proxy_protocol_addr",‘
        ‘"http_user_agent":"$http_user_agent",‘
        ‘"status":"$status"}‘;

    access_log  logs/access.log  access_json;

重启Nginx生效日志格式

[root@CentOS7-1 ~]#/apps/nginx/sbin/nginx -s reload

[root@CentOS7-1 ~]#tail -f /apps/nginx/logs/*.log
{"@timestamp":"2019-06-04T15:40:15+08:00","host":"192.168.36.110","clientip":"192.168.36.104","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"192.168.36.104","uri":"/index.html","domain":"192.168.36.104","xff":"192.168.36.1","referer":"-","tcp_xff":"","http_user_agent":"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:67.0) Gecko/20100101 Firefox/67.0","status":"304"}

更改Nginx日志为json格式

标签:window   logs   body   gecko   set   json   orm   rem   amp   

原文地址:https://blog.51cto.com/12980155/2404838

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!