Json 日志格式

作者: Alexander_Zz | 来源:发表于2019-05-03 09:41 被阅读0次

    更改 Nginx 日志格式为 Json 格式

    • 格式 1
    ~]# vim /usr/local/nginx/conf/nginx.conf
    
    log_format access2 '{"@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":"$request",'
            '"domain":"$host",'
            '"xff":"$http_x_forwarded_for",'
            '"referer":"$http_referer",'
            #'"user_agent":"$http_user_agent",'
            '"status":"$status"}';
    
    access_log  /var/www/logs/access.log  access2;
    
    • 格式 2
    ~]# vim /usr/local/nginx/conf/nginx.conf
    
    log_format  access_log_json  '{"user_ip":"$http_x_real_ip","lan_ip":"$remote_addr","log_time":"$time_iso8601","user_req":"$request","http_code":"$status","body_bytes_sent":"$body_bytes_sent","req_time":"$request_time","user_ua":"$http_user_agent"}';
    
    access_log  /var/www/logs/access.log  access_log_json;
    

    相关文章

      网友评论

        本文标题:Json 日志格式

        本文链接:https://www.haomeiwen.com/subject/bjjanqtx.html