温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nginx日志细节处理

发布时间:2020-10-19 13:23:02 来源:网络 阅读:448 作者:nineteens 栏目:开发技术

  Nginx 日志处理

  过滤冗杂日志

  使用官网默认模块 ngx_http_map_module过滤指定 URL 或者IP 不在日志中进行记录

  官网地址

  配置proxy

  proxy_set_header Host $host;

  proxy_set_header X-Real-IP $remote_addr;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  # $request_uri 系统内设变量

  # $loggable 自定义变量

  # if=$loggable 引用判断

  map $request_uri $loggable {

  "/" 0;

  "/health.html" 0;

  default 1;

  }

  log_format log_main '{"@timestamp":"$time_iso8601",'

  '"host":"$server_addr",'

  '"clientip":"$remote_addr",'

  '"size":$body_bytes_sent,'

  '"responsetime":$request_time,'

  '"upstreamtime":"$upstream_response_time",'

  '"upstreamhost":"$upstream_addr",'

  '"server_host":"$host",'

  '"url":"$uri",'

  '"url-info":"$request_uri",'

  '"xff":"$http_x_forwarded_for",'

  '"referer":"$http_referer",'

  '"agent":"$http_user_agent",'

  '"status":"$status"}';

  access_log /path/access.log log_main if=$loggable;

  配置 Nginx 获取真实IP

  配置阿里云 SLB 负载 ECS 服务器获取真实用户 IP

  官网地址无锡妇科医院排行榜 http://mobile.chfk120.com/

  意思是排除掉掉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",'

  '"host":"$server_addr",'

  '"clientip":"$remote_addr",'

  '"size":$body_bytes_sent,'

  '"responsetime":$request_time,'

  '"upstreamtime":"$upstream_response_time",'

  '"upstreamhost":"$upstream_addr",'

  '"server_host":"$host",'

  '"url":"$uri",'

  '"url-info":"$request_uri",'

  '"xff":"$http_x_forwarded_for",'

  '"referer":"$http_referer",'

  '"agent":"$http_user_agent",'

  '"status":"$status"}';

  access_log /path/access.log log_main;

  配置文件(http、server、location)增加段配置

  set_real_ip_from 100.64.0.0/10; # 阿里云 SLB 内网地址

  set_real_ip_from 172.17.0.0/16; # 过滤docker 内网 IP

  real_ip_header X-Forwarded-For;

  real_ip_recursive on;


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI