更改Nginx日誌爲json格式

  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"}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章