惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
Blog — PlanetScale
Blog — PlanetScale
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
D
DataBreaches.Net
L
LangChain Blog
F
Fortinet All Blogs
C
Check Point Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Help Net Security
J
Java Code Geeks
月光博客
月光博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
宝玉的分享
宝玉的分享
Jina AI
Jina AI

博客园 - lichdr

高德地图热力图的Flutter实现 App消息推送的简单实现 CAS的service参数验证 自定义Token的CAS登录 单元格的计算 表格行列的删除 表格行列的移动 FastReport的一些另类用法 FastReport分组页码 RFID会议签到系统总结(二十二)――系统中的模式 RFID会议签到系统总结(二十一)――服务端的通讯 RFID会议签到系统总结(二十)――数据窗体状态控制 RFID会议签到系统总结(十九)――单数据窗体 RFID会议签到系统总结(十八)――菜单与工具栏的加载 RFID会议签到系统总结(十七)――菜单与工具栏的改造(下) RFID会议签到系统总结(十六)――菜单与工具栏按钮的改造(上) RFID会议签到系统总结(十五)――管控端的窗体组织 RFID会议签到系统总结(十四)――管控端业务模块的加载 RFID会议签到系统总结(十三)――模块概述(下)
nginx访问日志过滤(多条件)
lichdr · 2023-07-05 · via 博客园 - lichdr

nginx的access_log的过滤网上有很多文章。是通过map定义一个变量,然后把那个变量配置到access_log的if即可。

比如:

map $status $loggable {
    ~^[23]  0;
    default 1;
}

access_log /path/to/access.log combined if=$loggable;

定义一个变量loggable,http状态码是2XX、3XX的返回0,其他情况返回1。然后access_log当loggable为0时就不记录。

但是我现在有两条件,一个是固定url,一个是负载均衡的心跳检测。

对于组合条件,这里的if不支持运算。

最后是在mpa定义变量时default用上一个变量的值解决的。配置如下:

 map $http_user_agent $health {
    default 1;
    ELB-HealthChecker/2.0 0;
 }

 map $uri $loggable {
    default $health;
    ~^/spicalURI* 0;
 }
 access_log  /var/log/nginx/access.log  main if=$loggable;

定义$loggable时用 default  $health 达到了“或”的效果。

这样nginx 的访问日志里就排除的这些访问量特别大又没啥信息量的项,避免日志过大。