主要为方便单用户请求日志回溯分析   记录用户标记。 将用户信息打印在access_log 日志里。

步骤:

1、重写nginx 的log格式

一般是地址是  /etc/nginx/conf.d/nginx_log_format.conf

自定义需要记录的字段

相关官方信息:

$upstream_http_name

keep server response header fields. For example, the “Server” response header field is available through the $upstream_http_server variable. The rules of converting header field names to variable names are the same as for the variables that start with the “$http_” prefix. Only the header fields from the response of the last server are saved.

log_format logstash '{ "http_host": "$http_host", "source_addr": "$http_x_forwarded_for", "http_code": "$status",  "bytes_sent": "$bytes_sent" , "hostname": "$hostname" , "player_id":"$upstream_http_player_id"

这里我加的是player_id

2、 在代码中设置 http response 的 header 值

以PHP 为例 :

header("player_id: xxxx ");

3、最后将格式配置到对应的server  access_log 中。

server {
listen 80;
server_name xxxxx;
charset utf-8;
root "xxxxx";
access_log /data/log/nginx/alice.access.log logstash;
error_log /data/log/nginx/alice.error.log;
}

效果:

这样我们就能在access_log 日志中记录玩家信息。  将日志同步到ES 中。我们就能更好的统计用户信息。

最新文章

  1. jsp使用EL表达式回传boolean值出错的问题
  2. 封装一个mysql类(ggshop)
  3. C# 获取本机指定类型指定网卡的Ip地址
  4. [ACM_几何] Fishnet
  5. Task异常处理
  6. php 继承
  7. Java数组运算
  8. RAID5和RAID10,哪种RAID更适合你(上)
  9. 亚马逊 在线测试题目 amazon (变种的)三叉树的最近公共祖先问题
  10. Javascript 性能优化的一点技巧
  11. PHP 字符串函数--替换、正则匹配等
  12. 网络编程中几个地址结构与转换(in_addr,sockaddr,sockaddr_in,pcap_addr)
  13. 简析TCP的三次握手与四次分手【转】
  14. 1.2 eclipse使用 :working set
  15. jQuery插件Flot的介绍
  16. convertView的疑问(软件管理器)
  17. bzoj:3400 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队
  18. springboot~@Valid注解对嵌套类型的校验
  19. 【案例分享】crontab执行脚本异常问题
  20. Badboy录制Jmter脚本

热门文章

  1. 老司机带大家领略MySQL中的乐观锁和悲观锁
  2. Appium移动自动化测试-----(八)定位控件
  3. SpringCloud服务注册与发现中心-Eureka
  4. Hive行列转换
  5. LeetCode 64. 最小路径和(Minimum Path Sum) 20
  6. 数据结构:队列queue 函数push() pop size empty front back
  7. 02 Python 函数的一些小笔记
  8. MGR安装记录
  9. hadoop 完全分布式搭建总结
  10. nodejs模块fs——文件操作api