Nginx 的 access log 如何以 json 形式记录?
Nginx 的 access log 默认是以空格分隔的字符串形式记录的,格式如下
log_format proxy '[$time_local] $remote_addr '
'$protocol $status $bytes_received $bytes_sent '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time" $upstream_session_time';
官方支持json格式
Syntax: | log_format |
---|---|
Default: | — |
Context: | stream |
Specifies the log format, for example:
log_format proxy '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
The escape
parameter (1.11.8) allows setting json
or default
characters escaping in variables, by default, default
escaping is used. The none
parameter (1.13.10) disables escaping.
这里需要注意的是从 1.11.8 开始 Nginx 已经支持 json 格式,如果版本低于这个建议使用 nginx-http-json-log 扩展
log_format json_combined escape=json '{"@timestamp":"$time_iso8601",'
'"@source":"$server_addr",'
'"@nginx_fields":{'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"body_bytes_sent":"$body_bytes_sent",'
'"request_time":"$request_time",'
'"status":"$status",'
'"host":"$host",'
'"uri":"$uri",'
'"server":"$server_name",'
'"port":"$server_port",'
'"protocol":"$server_protocol",'
'"request_uri":"$request_uri",'
'"request_body":"$request_body",'
'"request_method":"$request_method",'
'"http_referrer":"$http_referer",'
'"body_bytes_sent":"$body_bytes_sent",'
'"http_x_forwarded_for":"$http_x_forwarded_for",'
'"http_user_agent":"$http_user_agent",'
'"upstream_response_time":"$upstream_response_time",'
'"upstream_addr":"$upstream_addr"}}';
json格式比较直观,但数据量会变大
Nginx 的 access log 如何以 json 形式记录?的更多相关文章
- 在nginx日志access log可以记录POST请求的参数值
1) 在nginx日志access log可以记录POST请求的参数值 实现程度:日志中可以显示POST请求所提交的参数值 问题: 日志中文显示十六进制(在配置文件中配置中文也无效) 没有对 ...
- nginx的access.log文件详解
事实证明,日志文件真的是很重要很重要的.能够帮助我们快速的定位问题,并且知道用户访问的状态,浏览器,Ip,接口地址等,简直可怕.. 一.nginx的access.log(1)对博主而言,日志文件存放在 ...
- Nginx修改access.log日志时间格式
一.修改原因 因为要获取nginx访问信息,作为开发的数据使用,但是nginx的access.log文件中的默认的时间格式是这样的: [02/Nov/2017:20:48:25 +0800] 而要求的 ...
- shell定时统计Nginx下access.log的PV并发送给API保存到数据库
1,统计PV和IP 统计当天的PV(Page View) cat access.log | sed -n /`date "+%d\/%b\/%Y"`/p |wc -l 统计某一天的 ...
- 使用tcpdump 对nginx的access.log 非400的ip进行自动抓包
#抓取nginx access日志不是 400 的行,找出该ip ,并且启动抓包 #该脚本的执行要放在 crond 里面或者 while循环里面 ################## #网卡名称 ne ...
- nginx的access.log 和 error.log
nginx 常用的配置文件有两种: access.log 和 error.log access.log 的作用是 记录用户所有的访问请求,不论状态码,包括200 ,404,500等请求,404,500 ...
- 利用logrotate切割nginx的access.log日志
一.新建一个nginx的logrotate配置文件 /var/log/nginx/access.log { daily rotate compress delaycompress missingok ...
- nginx的access log按小时生成
1.在server或location段进行配置 if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})&q ...
- 在nginx日志的access log中记录post请求的参数值
背景:有时程序偶出现参数少了或没有提交到下一个链接Url里后出现问题,如何查呢,最好的办法是在nginx上的加post参数,以定位到问题才有可能对某个UIR的代码出现的问题进行排查. og_forma ...
随机推荐
- asp.net core系列 40 Web 应用MVC 介绍与详细示例
一. MVC介绍 MVC架构模式有助于实现关注点分离.视图和控制器均依赖于模型. 但是,模型既不依赖于视图,也不依赖于控制器. 这是分离的一个关键优势. 这种分离允许模型独立于可视化展示进行构建和测试 ...
- AndroidStudio运行java的main方法
新建一个java文件,含有main方法 package com.why.project.androidcnblogsdemo.utils; /** * Created by HaiyuKing * U ...
- 基于三层架构的增删改查Get知识点
给DataGridView控件绑定datatable数据源之后总是会多一行,在属性里修改属性allowuserToaddrow值为false即可 不可编辑状态是设置成只读状态即可,英文属性readon ...
- Chapter 5 Blood Type——25
"I usually am — but about what in particular this time?" “我通常都是 —— 但是这次有什么特殊的吗?” "Dit ...
- 【ASP.NET Core快速入门】(六)配置的热更新、配置的框架设计
配置的热更新 什么是热更新:一般来说,我们创建的项目都无法做到热更新:即项目无需重启,修改配置文件后读取到的信息就是修改配置之后的 我们只需要吧项目中用到的IOptions改成IOptionsSnap ...
- 环境与工具3:从打字开始 | vim | sublime
作为程序员,最不爽的一件事是被亲戚叫去修电脑. "喂,怎么跟你们讲,我是写代码的,不是修电脑的!什么?代码是什么?!" 小白:为什么程序员就不能修电脑了? 小程:会不会修都有可能, ...
- JSP面试题都在这里
下面是我整理下来的JSP知识点: 图上的知识点都可以在我其他的文章内找到相应内容. JSP常见面试题 jsp静态包含和动态包含的区别 jsp静态包含和动态包含的区别 在讲解request对象的时候,我 ...
- curl 错误总结
证书域名与访问的域名不一致 问题:curl SSL: certificate subject name 'luffichen_server.tencent.com' does not match ta ...
- js转base64(数字)
var name='测试文字'; var t_name=encodeURIComponent(name); t_name=window.btoa(t_name); console.log(t_name ...
- [转]GitLab-CI与GitLab-Runner
本文转自:https://www.jianshu.com/p/2b43151fb92e 一.持续集成(Continuous Integration) 要了解GitLab-CI与GitLab Runne ...