Nginx access_log日志添加返回字段
2024-08-27 02:58:46
主要为方便单用户请求日志回溯分析 记录用户标记。 将用户信息打印在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 中。我们就能更好的统计用户信息。
最新文章
- jsp使用EL表达式回传boolean值出错的问题
- 封装一个mysql类(ggshop)
- C# 获取本机指定类型指定网卡的Ip地址
- [ACM_几何] Fishnet
- Task异常处理
- php 继承
- Java数组运算
- RAID5和RAID10,哪种RAID更适合你(上)
- 亚马逊 在线测试题目 amazon (变种的)三叉树的最近公共祖先问题
- Javascript 性能优化的一点技巧
- PHP 字符串函数--替换、正则匹配等
- 网络编程中几个地址结构与转换(in_addr,sockaddr,sockaddr_in,pcap_addr)
- 简析TCP的三次握手与四次分手【转】
- 1.2 eclipse使用 :working set
- jQuery插件Flot的介绍
- convertView的疑问(软件管理器)
- bzoj:3400 [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队
- springboot~@Valid注解对嵌套类型的校验
- 【案例分享】crontab执行脚本异常问题
- Badboy录制Jmter脚本