米狗

  • kubernets
  • docker
  • AWS
  • linux
  • nginx
Kratos
  1. 首页
  2. 中间件
  3. nginx
  4. 正文

nginx配置json日志

2021年6月23日 904点热度 0人点赞 0条评论

修改nginx配置文件,增加log_json的日志格式,同时修改主配置文件日志格式为log_json。

log_format log_json '{"@timestamp": "$time_local", '
'"remote_addr": "$remote_addr", '
'"referer": "$http_referer", '
'"request": "$request", '
'"status": $status, '
'"bytes": $body_bytes_sent, '
'"agent": "$http_user_agent", '
'"x_forwarded": "$http_x_forwarded_for", '
'"upstream_addr": "$upstream_addr",'
'"upstream_host": "$upstream_http_host",'
'"upstream_reponse_time": "$upstream_response_time",'
'"request_time": "$request_time",'
'"request_body": "$request_body"}';

 

下面是log_format指令中常用的一些变量:

变量 含义
$bytes_sent 发送给客户端的总字节数
$body_bytes_sent 发送给客户端的字节数,不包括响应头的大小
$connection 连接序列号
$connection_requests 当前通过连接发出的请求数量
$msec 日志写入时间,单位为秒,精度是毫秒
$pipe 如果请求是通过http流水线发送,则其值为"p",否则为“."
$request_length 请求长度(包括请求行,请求头和请求体)
$request_time 请求处理时长,单位为秒,精度为毫秒,从读入客户端的第一个字节开始,直到把最后一个字符发送张客户端进行日志写入为止
$status 响应状态码
$time_iso8601 标准格式的本地时间,形如“2017-05-24T18:31:27+08:00”
$time_local 通用日志格式下的本地时间,如"24/May/2017:18:31:27 +0800"
$http_referer 请求的referer地址。
$http_user_agent 客户端浏览器信息。
$remote_addr 客户端IP
$http_x_forwarded_for 当前端有代理服务器时,设置web节点记录客户端地址的配置,此参数生效的前提是代理服务器也要进行相关的x_forwarded_for设置。
$request 完整的原始请求行,如 "GET / HTTP/1.1"
$remote_user 客户端用户名称,针对启用了用户认证的请求
$request_uri 完整的请求地址,如 "https://daojia.com/"
————————————————
版权声明:本文为CSDN博主「biubiuli」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/biubiuli/article/details/79481882

 

标签: 暂无
最后更新:2021年6月30日

duhongjun

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

您需要 登录 之后才可以评论

归档

  • 2024 年 10 月
  • 2024 年 4 月
  • 2024 年 3 月
  • 2024 年 2 月
  • 2024 年 1 月
  • 2023 年 11 月
  • 2023 年 4 月
  • 2023 年 2 月
  • 2023 年 1 月
  • 2022 年 11 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 8 月
  • 2021 年 12 月
  • 2021 年 11 月
  • 2021 年 8 月
  • 2021 年 7 月
  • 2021 年 6 月
  • 2021 年 2 月
  • 2020 年 1 月
  • 2019 年 12 月
  • 2019 年 11 月
  • 2019 年 10 月
  • 2019 年 9 月
  • 2019 年 8 月

分类目录

  • AWS
  • docker
  • elasticsearch
  • Jenkins
  • kubernets
  • linux
  • mysql
  • nginx
  • Oracle
  • php
  • redis
  • zabbix
  • 个人
  • 中间件
  • 公有云
  • 大数据
  • 安全工具
  • 微软
  • 操作系统
  • 数据库
  • 未分类
  • 监控
  • 科技
  • 网络技术
  • 资讯
  • 阿里云

COPYRIGHT © 2024 米狗. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

沪ICP备2021019346号-1