nginx 日志记录 自定义详解

 

1、log_format 普通格式

log_format main '$remote_addr - $remote_user [$time_local] $request '
                '"$status" $body_bytes_sent "$http_referer" '
                '"$http_user_agent" "$http_x_forwarded_for" "$request_time" "$upstream_response_time"';

2、log_format JSON 格式

log_format logJson '{
"@timestamp": "$time_local", '
'"@fields": { '
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"body_bytes_sent": "$body_bytes_sent", '
'"request_time": "$request_time", '
'"status": "$status", '
'"request": "$request", '
'"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" }
}';

3、指定日志格式

access_log  /data/logs/nginx/access.log  logJson buffer=32k;
access_log  /data/logs/nginx/access.log  main buffer=32k; 

4、字段释义

字段

说明

$remote_addr 客户端地址
$remote_user 客户端用户名称
$time_local 访问时间和时区
$request 请求的URI和HTTP协议
$http_host 请求地址,即浏览器中你输入的地址(IP或域名)
$status HTTP请求状态
$upstream_status upstream状态
$body_bytes_sent 发送给客户端文件内容大小
$http_referer url跳转来源
$http_user_agent 用户终端浏览器等信息
$ssl_protocol SSL协议版本
$ssl_cipher 交换数据中的算法
$upstream_addr 后台upstream的地址,即真正提供服务的主机地址
$request_time 整个请求的总时间
$upstream_response_time 请求过程中,upstream响应时间

最新文章

  1. Mysql中的存储过程
  2. Codeforces 567D One-Dimensional Battle Ships
  3. Windows下文件的所有和权限
  4. WEB前端介绍
  5. Android Fragment 多标签应用
  6. cf D Bear and Floodlight
  7. JVM内存管理 (转)
  8. 递归遍历XML所有节点
  9. service structure flowchart with full stack functionality in a brife map
  10. 编写一个python脚本功能-备份
  11. xdu_1165:均值滤波
  12. Python入门之装饰器九步学习入门
  13. WebGL或OpenGL关于模型视图投影变换的设置技巧
  14. ddt源码修改:HtmlTestRunner报告依据接口名显示用例名字
  15. Django 安装 创建项目
  16. 第五篇、Python之迭代器与生成器
  17. Java工具之上传文件
  18. Ajax中onreadystatechange函数不执行,是因为放在open()后
  19. MySql 数据库安装、环境变量配置 以及 本地连接
  20. linux基础之bash特性

热门文章

  1. leetcode-distinct sequences
  2. application/x-www-form-urlencode 和 multiple/form-data
  3. git-day1-安装和基础使用
  4. Geekforgeek week1
  5. PHP 字符串补0
  6. D3——根据数据画图
  7. ORACLE查询删除重复记录
  8. ui-element消息类型 MessageBox 弹框 type类型
  9. Mobile IP
  10. Subnet Routing Examples