更改Nginx日誌爲json格式

  Nginx是最經常使用的web服務器,其能夠承受的併發訪問量遠遠大於apache,經過將nginx保存爲json格式,而後對日誌進行分析展現,可以獲取到不少更直觀的信息,而後加以統計,能夠進行更多的數據展現。html

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"}
相關文章
相關標籤/搜索