从零编写日志分析系统之nginx日志配置

配置nginx日志文件

nginx原有的配置文件包含的信息比较少,可以修改nginx.conf得到更多的数据。

nginx日志文件输出形式有三种形式,最常见的就是通过空格区分字段输出。还有通过自定义json形式输出,通过syslog直接输出到远端服务。

  • 通过空格区分输出
log_format  main  '$remote_addr $remote_user [$time_local] "$request" $http_host '
        '$status $upstream_status $body_bytes_sent "$http_referer"'
        '"$http_user_agent$ssl_protocol $ssl_cipher $upstream_addr '
        '$request_time $upstream_response_time';
  • 通过自定义json输出
 - log_format json '{"@timestamp":"$time_iso8601",'
'"host":"$server_addr",'
'"clientip":"$remote_addr",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"http_host":"$host",'
'"url":"$uri",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"agent":"$http_user_agent",'
'"status":"$status"}';
  • 发送到远端服务
 - access_log syslog:server=unix:/data0/rsyslog/nginx.sock locallog;
  • 发送到logstarsh
access_log syslog:server=192.168.0.2:5140,facility=local6,tag=ng
inx_access,severity=info logstashlog;

附录:nginx日志参数说明
参考:ELK stack中文指南

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值