Nginx日志处理
过滤冗杂日志
使用官网默认模块ngx_http_map_module过滤指定URL或者的IP不在日志中进行记录
官网地址
配置代理
proxy_set_header主机主机美元;
proxy_set_header X-Real-IP remote_addr美元;
proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for美元;
# $ request_uri系统内设变量
# $ loggable自定义变量
#如果=$ loggable引用判断
地图request_uri loggable美元{
" 0;
"/健康。html“0;
默认1;
}
log_format log_main”{“@timestamp”:“time_iso8601美元”,
的“主机”:“server_addr美元”,“
”“clientip”:“remote_addr美元”,
的“大小”:body_bytes_sent美元,”
“responsetime”: request_time美元,”
“upstreamtime”:“upstream_response_time美元”,“
”“upstreamhost”:“upstream_addr美元”,“
”“server_host”:“美元主机”,“
”“url”:“uri”美元,”
“url信息”:“request_uri美元”,“
”“xff”:“http_x_forwarded_for美元”,
的“推荐人”:“http_referer美元”,
的“代理”:“http_user_agent美元”,
的“状态”:“地位”美元}的;
access_log/道路/访问。日志log_main如果=$ loggable;
配置Nginx获取真实IP
配置阿里云SLB负载ECS服务器获取真实用户IP
官网地址
意思是排除掉掉set_real_ip_from 100.64.0.0/10中的IP剩下的IP就是用户真实IP
确认Nginx安装了realip模块
#可在编译过程增加,with-http_realip_module
Nginx - v | grep realip
配置对应的配置文件
log_format log_main”{“@timestamp”:“time_iso8601美元”,
的“主机”:“server_addr美元”,“
”“clientip”:“remote_addr美元”,
的“大小”:body_bytes_sent美元,”
“responsetime”: request_time美元,”
“upstreamtime”:“upstream_response_time美元”,“
”“upstreamhost”:“upstream_addr美元”,“
”“server_host”:“美元主机”,“
”“url”:“uri”美元,”
“url信息”:“request_uri美元”,“
”“xff”:“http_x_forwarded_for美元”,
的“推荐人”:“http_referer美元”,
的“代理”:“http_user_agent美元”,
的“状态”:“地位”美元}的;
access_log/道路/访问。日志log_main;
配置文件(http、服务器位置)增加段配置
set_real_ip_from 100.64.0.0/10;#阿里云SLB内网地址
set_real_ip_from 172.17.0.0/16;#过滤码头工人内网IP
real_ip_header X-Forwarded-For;
real_ip_recursive;